Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 6 additions & 63 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Assume Explicit For: yes
Die On: warning
</pre>

<pre class="link-defaults">
spec:writing-assistance-apis; type:dfn; text:get the language availabilities partition
spec:writing-assistance-apis; type:dfn; text:compute language availability
</pre>

<pre class="anchors">
urlPrefix: https://tc39.es/ecma402/; spec: ECMA-402
type: dfn; text: [[AvailableLocales]]; url: sec-internal-slots
Expand Down Expand Up @@ -228,7 +233,7 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
<div class="example" id="example-subtags-chinese">
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.

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`".
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="https://webmachinelearning.github.io/writing-assistance-apis/#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`".

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

Expand All @@ -254,73 +259,11 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };

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

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]]

A <dfn>language availabilities double</dfn> is a [=struct=] with the following [=struct/items=]:

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

<div algorithm>
To <dfn export>get the language availabilities partition</dfn> given a description |purpose| of the purpose for which we're checking language availability:

1. Let |partition| be «[ "{{Availability/available}}" → an empty [=set=], "{{Availability/downloading}}" → an empty [=set=], "{{Availability/downloadable}}" → an empty [=set=] ]».

1. [=list/For each=] human language |languageTag|, represented as a [=Unicode canonicalized locale identifier=], for which the user agent [=model availability/currently supports=] |purpose|:

1. [=set/Append=] |languageTag| to |partition|["{{Availability/available}}"].

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:

1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloading}}"].

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:

1. [=set/Append=] |languageTag| to |partition|["{{Availability/downloadable}}"].

1. [=Assert=]: |partition|["{{Availability/available}}"], |partition|["{{Availability/downloading}}"], and |partition|["{{Availability/downloadable}}"] are disjoint.

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:

1. Let |missingLanguageTags| be the [=set=] of missing language tags necessary for that union to meet the language tag set completeness rules.

1. [=set/For each=] |languageTag| of |missingLanguageTags|:

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.

1. Return |partition|.
</div>

<div algorithm>
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.

1. Let |availability| be "{{Availability/available}}".

1. [=set/For each=] |language| of |requestedLanguages|:

1. Let |unavailable| be true.

1. [=list/For each=] |availabilityToCheck| of « "{{Availability/available}}", "{{Availability/downloading}}", "{{Availability/downloadable}}" »:

1. Let |languagesWithThisAvailability| be |partition|[|availabilityToCheck|].

1. Let |bestMatch| be [$LookupMatchingLocaleByBestFit$](|languagesWithThisAvailability|, « |language| »).

1. If |bestMatch| is not undefined, then:

1. [=list/Replace=] |language| with |bestMatch|.\[[locale]] in |requestedLanguages|.

1. Set |availability| to the [=Availability/minimum availability=] given |availability| and |availabilityToCheck|.

1. Set |unavailable| to false.

1. [=iteration/Break=].

1. If |unavailable| is true, then return "{{Availability/unavailable}}".

1. Return |availability|.
</div>

<h3 id="the-proofreader-class">The {{Proofreader}} class</h3>

Every {{Proofreader}} has a <dfn for="Proofreader">include correction type</dfn>, a [=boolean=] or default to false, set during creation.
Expand Down
Loading