Skip to content

Commit 76dff6d

Browse files
authored
Update spec: language availabilities and fix build error
1 parent 13f7221 commit 76dff6d

File tree

1 file changed

+78
-9
lines changed

1 file changed

+78
-9
lines changed

index.bs

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
157157
: correction explanation language
158158
:: |options|["{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}"] if it [=map/exists=]; otherwise null
159159
</dl>
160-
</div>
160+
</div>
161161

162162
<h3 id="proofreader-availability">Availability</h3>
163163

164164
<div algorithm>
165165
The static <dfn method for="Proofreader">availability(|options|)</dfn> method steps are:
166166

167167
1. Return the result of [=computing AI model availability=] given |options|, "{{Proofreader}}", [=validate and canonicalize proofreader options=], and [=compute proofreader options availability=].
168-
</div>
168+
</div>
169169

170170
<div algorithm>
171171
To <dfn>compute proofreader options availability</dfn> given a {{ProofreaderCreateCoreOptions}} |options|, perform the following steps. They return either an {{Availability}} value or null, and they mutate |options| in place to update language tags to their best-fit matches.
@@ -186,8 +186,8 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
186186

187187
1. Set |options|["{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}"] to |correctionExplanationLanguagesList|[0].
188188

189-
1. Return the [=Availability/minimum availability=] given « |availability|, |inputLanguageAvailability|, |contextLanguagesAvailability|, |correctionExplanationLanguageAvailability| ».
190-
</div>
189+
1. Return the [=Availability/minimum availability=] given « |availability|, |inputLanguageAvailability|, |correctionExplanationLanguageAvailability| ».
190+
</div>
191191

192192
<div algorithm>
193193
The <dfn>proofreader non-language options availability</dfn>, given a boolean |includeCorrectionTypes| and a boolean |includeCorrectionExplanations|, is given by the following steps. They return an {{Availability}} value or null.
@@ -203,7 +203,7 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
203203
1. If the user agent believes it will be able to [=model availability/support=] proofreading text according to |includeCorrectionTypes| and |includeCorrectionExplanations|, but only after performing a not-currently-ongoing download, then return "{{Availability/downloadable}}".
204204

205205
1. Otherwise, return "{{Availability/unavailable}}".
206-
</div>
206+
</div>
207207

208208
<div algorithm>
209209
The <dfn>proofreader language availabilities double</dfn> is given by the following steps. They return a [=language availabilities double=] or null.
@@ -220,8 +220,8 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
220220

221221
: [=language availabilities double/correction explanation languages=]
222222
:: the result of [=getting the language availabilities partition=] given the purpose of producing text explanations of proofreading corrections in that language
223-
</dl>
224-
</div>
223+
</dl>
224+
</div>
225225

226226
<div class="example" id="example-subtags-chinese">
227227
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 summarizing text written in traditional Chinese with no downloads, and simplified Chinese after a download.
@@ -247,8 +247,77 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
247247

248248
await a("zh-BR") === "downloadable"; // zh-BR will best-fit to zh
249249
await a("zh-Kana") === "downloadable"; // zh-Kana will best-fit to zh
250-
</xmp>
251-
</div>
250+
</xmp>
251+
</div>
252+
253+
<h3 id="supporting-language-availability">Language availability</h3>
254+
255+
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]]
256+
257+
A <dfn>language availabilities double</dfn> is a [=struct=] with the following [=struct/items=]:
258+
259+
* <dfn for="language availabilities double">input languages</dfn>, a [=language availabilities partition=]
260+
* <dfn for="language availabilities double">correction explanation languages</dfn>, a [=language availabilities partition=]
261+
262+
<div algorithm>
263+
To <dfn export>get the language availabilities partition</dfn> given a description |purpose| of the purpose for which we're checking language availability:
264+
265+
1. Let |partition| be «[ "{{Availability/available}}" → an empty [=set=], "{{Availability/downloading}}" → an empty [=set=], "{{Availability/downloadable}}" → an empty [=set=] ]».
266+
267+
1. [=list/For each=] human language |languageTag|, represented as a [=Unicode canonicalized locale identifier=], for which the user agent [=model availability/currently supports=] |purpose|:
268+
269+
1. [=set/Append=] |languageTag| to |partition|["{{Availability/available}}"].
270+
271+
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:
272+
273+
1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloading}}"].
274+
275+
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:
276+
277+
1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloadable}}"].
278+
279+
1. [=Assert=]: |partition|["{{Availability/available}}"], |partition|["{{Availability/downloading}}"], and |partition|["{{Availability/downloadable}}"] are disjoint.
280+
281+
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:
282+
283+
1. Let |missingLanguageTags| be the [=set=] of missing language tags necessary for that union to meet the [=language tag set completeness rules=].
284+
285+
1. [=set/For each=] |languageTag| of |missingLanguageTags|:
286+
287+
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.
288+
289+
1. Return |partition|.
290+
</div>
291+
292+
<div algorithm>
293+
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.
294+
295+
1. Let |availability| be "{{Availability/available}}".
296+
297+
1. [=set/For each=] |language| of |requestedLanguages|:
298+
299+
1. Let |unavailable| be true.
300+
301+
1. [=list/For each=] |availabilityToCheck| of « "{{Availability/available}}", "{{Availability/downloading}}", "{{Availability/downloadable}}" »:
302+
303+
1. Let |languagesWithThisAvailability| be |partition|[|availabilityToCheck|].
304+
305+
1. Let |bestMatch| be [$LookupMatchingLocaleByBestFit$](|languagesWithThisAvailability|, « |language| »).
306+
307+
1. If |bestMatch| is not undefined, then:
308+
309+
1. [=list/Replace=] |language| with |bestMatch|.\[[locale]] in |requestedLanguages|.
310+
311+
1. Set |availability| to the [=Availability/minimum availability=] given |availability| and |availabilityToCheck|.
312+
313+
1. Set |unavailable| to false.
314+
315+
1. [=iteration/Break=].
316+
317+
1. If |unavailable| is true, then return "{{Availability/unavailable}}".
318+
319+
1. Return |availability|.
320+
</div>
252321

253322
<h2 id="supporting">Shared infrastructure</h2>
254323

0 commit comments

Comments
 (0)