Skip to content

Commit 35c7496

Browse files
committed
Remove duplicate language availability definitions
The definitions of the "computing language availability" and "getting the language availabilities partition" algorithms as well as the "language availabilities partition" concept are already present in the Writing Assistance APIs specification. This change removes them from the Prooferreader API specification.
1 parent 67e3891 commit 35c7496

1 file changed

Lines changed: 8 additions & 64 deletions

File tree

index.bs

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ Assume Explicit For: yes
1515
Die On: warning
1616
</pre>
1717

18+
<pre class="link-defaults">
19+
spec: writing-assistance-apis
20+
type: dfn; text: computing language availability
21+
type: dfn; text: getting the language availabilities partition
22+
type: dfn; text: language availabilities partition
23+
</pre>
24+
1825
<pre class="anchors">
1926
urlPrefix: https://tc39.es/ecma402/; spec: ECMA-402
2027
type: dfn; text: [[AvailableLocales]]; url: sec-internal-slots
@@ -228,7 +235,7 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
228235
<div class="example" id="example-subtags-chinese">
229236
A common setup seen in today's software is to support two types of written Chinese: "traditional Chinese" and "simplified Chinese". Let's suppose that the user agent supports proofreading text written in traditional Chinese with no downloads, and simplified Chinese after a download.
230237

231-
One way this could be implemented would be for [=proofreader language availabilities double=] to return that "`zh-Hant`" is in the [=language availabilities double/input languages=]["{{Availability/available}}"] set, and "`zh`" and "`zh-Hans`" are in the [=language availabilities double/input languages=]["{{Availability/downloadable}}"] set. This return value conforms to the requirements of the language tag set completeness rules, in ensuring that "`zh`" is present. Per <a class="allow-2119" href="#language-tag-completeness-implementation-defined">the "should"-level guidance</a>, the implementation has determined that "`zh`" belongs in the set of downloadable input languages, with "`zh-Hans`", instead of in the set of available input languages, with "`zh-Hant`".
238+
One way this could be implemented would be for [=proofreader language availabilities double=] to return that "`zh-Hant`" is in the [=language availabilities double/input languages=]["{{Availability/available}}"] set, and "`zh`" and "`zh-Hans`" are in the [=language availabilities double/input languages=]["{{Availability/downloadable}}"] set. This return value conforms to the requirements of the language tag set completeness rules, in ensuring that "`zh`" is present. Per the [=get the language availabilities partition=] algorithm steps, the implementation has determined that "`zh`" belongs in the set of downloadable input languages, with "`zh-Hans`", instead of in the set of available input languages, with "`zh-Hant`".
232239

233240
Combined with the use of [$LookupMatchingLocaleByBestFit$], this means {{Proofreader/availability()}} will give the following answers:
234241

@@ -254,73 +261,11 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
254261

255262
<h3 id="supporting-language-availability">Language availability</h3>
256263

257-
A <dfn>language availabilities partition</dfn> is a [=map=] whose [=map/keys=] are "{{Availability/downloading}}", "{{Availability/downloadable}}", or "{{Availability/available}}", and whose [=map/values=] are [=sets=] of strings representing [=Unicode canonicalized locale identifiers=]. [[!ECMA-402]]
258-
259264
A <dfn>language availabilities double</dfn> is a [=struct=] with the following [=struct/items=]:
260265

261266
* <dfn for="language availabilities double">input languages</dfn>, a [=language availabilities partition=]
262267
* <dfn for="language availabilities double">correction explanation languages</dfn>, a [=language availabilities partition=]
263268

264-
<div algorithm>
265-
To <dfn export>get the language availabilities partition</dfn> given a description |purpose| of the purpose for which we're checking language availability:
266-
267-
1. Let |partition| be «[ "{{Availability/available}}" → an empty [=set=], "{{Availability/downloading}}" → an empty [=set=], "{{Availability/downloadable}}" → an empty [=set=] ]».
268-
269-
1. [=list/For each=] human language |languageTag|, represented as a [=Unicode canonicalized locale identifier=], for which the user agent [=model availability/currently supports=] |purpose|:
270-
271-
1. [=set/Append=] |languageTag| to |partition|["{{Availability/available}}"].
272-
273-
1. [=list/For each=] human language |languageTag|, represented as a [=Unicode canonicalized locale identifier=], for which the user agent believes it will be able to [=model availability/support=] |purpose|, but only after finishing a download that is already ongoing:
274-
275-
1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloading}}"].
276-
277-
1. [=list/For each=] human language |languageTag|, represented as a [=Unicode canonicalized locale identifier=], for which the user agent believes it will be able to [=model availability/support=] |purpose|, but only after performing a not-currently-ongoing download:
278-
279-
1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloadable}}"].
280-
281-
1. [=Assert=]: |partition|["{{Availability/available}}"], |partition|["{{Availability/downloading}}"], and |partition|["{{Availability/downloadable}}"] are disjoint.
282-
283-
1. If the [=set/union=] of |partition|["{{Availability/available}}"], |partition|["{{Availability/downloading}}"], and |partition|["{{Availability/downloadable}}"] does not meet the language tag set completeness rules, then:
284-
285-
1. Let |missingLanguageTags| be the [=set=] of missing language tags necessary for that union to meet the language tag set completeness rules.
286-
287-
1. [=set/For each=] |languageTag| of |missingLanguageTags|:
288-
289-
1. <span id="language-tag-completeness-implementation-defined"></span> [=set/Append=] |languageTag| to one of the three sets. Which of the sets to append to is [=implementation-defined=], and should be guided by considerations similar to that of [$LookupMatchingLocaleByBestFit$] in terms of keeping "best fallback languages" together.
290-
291-
1. Return |partition|.
292-
</div>
293-
294-
<div algorithm>
295-
To <dfn export>compute language availability</dfn> given an [=ordered set=] of strings |requestedLanguages| and a [=language availabilities partition=] |partition|, perform the following steps. They return an {{Availability}} value, and they mutate |requestedLanguages| in place to update language tags to their best-fit matches.
296-
297-
1. Let |availability| be "{{Availability/available}}".
298-
299-
1. [=set/For each=] |language| of |requestedLanguages|:
300-
301-
1. Let |unavailable| be true.
302-
303-
1. [=list/For each=] |availabilityToCheck| of « "{{Availability/available}}", "{{Availability/downloading}}", "{{Availability/downloadable}}" »:
304-
305-
1. Let |languagesWithThisAvailability| be |partition|[|availabilityToCheck|].
306-
307-
1. Let |bestMatch| be [$LookupMatchingLocaleByBestFit$](|languagesWithThisAvailability|, « |language| »).
308-
309-
1. If |bestMatch| is not undefined, then:
310-
311-
1. [=list/Replace=] |language| with |bestMatch|.\[[locale]] in |requestedLanguages|.
312-
313-
1. Set |availability| to the [=Availability/minimum availability=] given |availability| and |availabilityToCheck|.
314-
315-
1. Set |unavailable| to false.
316-
317-
1. [=iteration/Break=].
318-
319-
1. If |unavailable| is true, then return "{{Availability/unavailable}}".
320-
321-
1. Return |availability|.
322-
</div>
323-
324269
<h3 id="the-proofreader-class">The {{Proofreader}} class</h3>
325270

326271
Every {{Proofreader}} has a <dfn for="Proofreader">include correction type</dfn>, a [=boolean=] or default to false, set during creation.
@@ -545,4 +490,3 @@ Please see [[WRITING-ASSISTANCE-APIS#privacy]] for a discussion of privacy consi
545490
<h2 id="security">Security considerations</h2>
546491

547492
Please see [[WRITING-ASSISTANCE-APIS#security]] for a discussion of security considerations for the translator and language detector APIs. That text was written to apply to all APIs sharing the same infrastructure, as noted in [[#dependencies]].
548-

0 commit comments

Comments
 (0)