forked from tc39/proposal-intl-enumeration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include aliases in the Available operations
The Available abstract operations (e.g. AvailableCalendars) should return all possible aliases, so that other places in the spec (e.g. the Temporal.Calendar constructor) can use them to determine whether a given input value is valid. This input value can subsequently be canonicalized by another abstract operation (e.g. CanonicalizeCalendar). In Intl.supportedValuesOf(), on the other hand, we should _not_ return all possible aliases, so we filter them out using a Canonicalize operation before returning the list of Available codes as an array to the caller. Not all of the kinds of codes here have aliases, and not even all of them have a concept of "canonical". A quick investigation shows: - Calendar: aliased; case-regularized; limited values "available" but any well-formed value accepted, unknown values coerced to the locale's default - Collation: not aliased; case-regularized; limited values "available" but any well-formed value accepted, unknown values coerced to the locale's default - Currency: not sure if it is aliased because I don't have a copy of ISO 4217; case-regularized; limited values "available" but any well-formed value accepted and used - Numbering system: not aliased; not case-regularized; limited values "available" but any well-formed value accepted, unknown values coerced to the locale's default - Time zone: aliased; case-regularized - Unit of measurement: not aliased; not case-regularized; limited values "available" but simple combinations of core values also accepted and used So, I conclude that we need Canonicalize operations for calendars, time zones, and possibly currency units. An alternative approach would be to write Canonicalize operations for all of the kinds of codes, and have them perform the case-regularization (or for numbering systems and units of measurement they would be no-ops). Closes: tc39#37
- Loading branch information
Showing
6 changed files
with
158 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<emu-clause id="intl-displaynames-objects"> | ||
<h1>DisplayNames Objects</h1> | ||
|
||
<p>...</p> | ||
|
||
<emu-clause id="sec-intl-displaynames-abstracts"> | ||
<h1>Abstract Operations for DisplayNames Objects</h1> | ||
|
||
<emu-clause id="sec-canonicalcodefordisplaynames" aoid="CanonicalCodeForDisplayNames"> | ||
<h1>CanonicalCodeForDisplayNames ( _type_, _code_ )</h1> | ||
<p> | ||
The CanonicalCodeForDisplayNames abstract operation takes arguments _type_ (a String) and _code_ (a String). It verifies that the _code_ argument represents a well-formed code according to the _type_ argument and returns the case-regularized form of the _code_. The algorithm refers to <a href="https://www.unicode.org/reports/tr35/#Identifiers">UTS 35's Unicode Language and Locale Identifiers grammar</a>. The following steps are taken: | ||
</p> | ||
<emu-alg> | ||
1. If _type_ is *"language"*, then | ||
1. If _code_ does not match the `unicode_language_id` production, throw a *RangeError* exception. | ||
1. If ! IsStructurallyValidLanguageTag(_code_) is *false*, throw a *RangeError* exception. | ||
1. Return ! CanonicalizeUnicodeLocaleId(_code_). | ||
1. If _type_ is *"region"*, then | ||
1. If _code_ does not match the `unicode_region_subtag` production, throw a *RangeError* exception. | ||
1. Return the ASCII-uppercase of _code_. | ||
1. If _type_ is *"script"*, then | ||
1. If _code_ does not match the `unicode_script_subtag` production, throw a *RangeError* exception. | ||
1. Assert: The length of _code_ is 4, and every code unit of _code_ represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive). | ||
1. Let _first_ be the ASCII-uppercase of the substring of _code_ from 0 to 1. | ||
1. Let _rest_ be the ASCII-lowercase of the substring of _code_ from 1. | ||
1. Return the string-concatenation of _first_ and _rest_. | ||
1. If _type_ is *"calendar"*, then | ||
1. If _code_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception. | ||
1. If _code_ uses any of the backwards compatibility syntax described in <a href="https://unicode.org/reports/tr35/#BCP_47_Conformance">Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance</a>, throw a *RangeError* exception. | ||
1. Return the ASCII-lowercase of _code_. | ||
1. If _type_ is *"dateTimeField"*, then | ||
1. If the result of IsValidDateTimeFieldCode(_code_) is *false*, throw a *RangeError* exception. | ||
1. Return _code_. | ||
1. Assert: _type_ is *"currency"*. | ||
1. If ! IsWellFormedCurrencyCode(_code_) is *false*, throw a *RangeError* exception. | ||
1. Return <del>the ASCII-uppercase of _code_</del><ins>CanonicalizeCurrency(_code_)</ins>. | ||
</emu-alg> | ||
</emu-clause> | ||
</emu-clause> | ||
</emu-clause> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<emu-clause id="numberformat-objects"> | ||
<h1>NumberFormat Objects</h1> | ||
|
||
<emu-clause id="sec-intl-numberformat-constructor"> | ||
<h1>The Intl.NumberFormat Constructor</h1> | ||
|
||
<p>...</p> | ||
|
||
<emu-clause id="sec-setnumberformatunitoptions" aoid="SetNumberFormatUnitOptions"> | ||
<h1>SetNumberFormatUnitOptions ( _intlObj_, _options_ )</h1> | ||
<p> | ||
The abstract operation SetNumberFormatUnitOptions resolves the user-specified options relating to units onto the intl object. | ||
</p> | ||
<emu-alg> | ||
1. Assert: Type(_intlObj_) is Object. | ||
1. Assert: Type(_options_) is Object. | ||
1. Let _style_ be ? GetOption(_options_, *"style"*, *"string"*, « *"decimal"*, *"percent"*, *"currency"*, *"unit"* », *"decimal"*). | ||
1. Set _intlObj_.[[Style]] to _style_. | ||
1. Let _currency_ be ? GetOption(_options_, *"currency"*, *"string"*, *undefined*, *undefined*). | ||
1. If _currency_ is *undefined*, then | ||
1. If _style_ is *"currency"*, throw a *TypeError* exception. | ||
1. Else, | ||
1. If ! IsWellFormedCurrencyCode(_currency_) is *false*, throw a *RangeError* exception. | ||
1. Let _currencyDisplay_ be ? GetOption(_options_, *"currencyDisplay"*, *"string"*, « *"code"*, *"symbol"*, *"narrowSymbol"*, *"name"* », *"symbol"*). | ||
1. Let _currencySign_ be ? GetOption(_options_, *"currencySign"*, *"string"*, « *"standard"*, *"accounting"* », *"standard"*). | ||
1. Let _unit_ be ? GetOption(_options_, *"unit"*, *"string"*, *undefined*, *undefined*). | ||
1. If _unit_ is *undefined*, then | ||
1. If _style_ is *"unit"*, throw a *TypeError* exception. | ||
1. Else, | ||
1. If ! IsWellFormedUnitIdentifier(_unit_) is *false*, throw a *RangeError* exception. | ||
1. Let _unitDisplay_ be ? GetOption(_options_, *"unitDisplay"*, *"string"*, « *"short"*, *"narrow"*, *"long"* », *"short"*). | ||
1. If _style_ is *"currency"*, then | ||
1. Set _intlObj_.[[Currency]] to <del>the ASCII-uppercase of _currency_</del><ins>CanonicalizeCurrency(_currency_)</ins>. | ||
1. Set _intlObj_.[[CurrencyDisplay]] to _currencyDisplay_. | ||
1. Set _intlObj_.[[CurrencySign]] to _currencySign_. | ||
1. If _style_ is *"unit"*, then | ||
1. Set _intlObj_.[[Unit]] to _unit_. | ||
1. Set _intlObj_.[[UnitDisplay]] to _unitDisplay_. | ||
</emu-alg> | ||
</emu-clause> | ||
</emu-clause> | ||
|
||
<p>...</p> | ||
</emu-clause> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters