diff --git a/intl.emu b/intl.emu index bda12cd4..7661d9a4 100644 --- a/intl.emu +++ b/intl.emu @@ -11,6 +11,172 @@
+
+ Unit category data is derived from CLDR file
+ validity/unit.xml.
+ As described in Unicode Technical Standard #35 Part 1 Core, Validity Data,
+ the body of the <id type='unit' idStatus='regular'> element contains
+ the supported units, represented as a whitespace-separated list in which each element is a sequence of subtags separated by *"-"* (U+002D HYPHEN-MINUS) characters.
+ For each unit, the first subtag provides the unit category, and the remaining subtags are the unit identifier.
+
Unit preference data is derived from CLDR file supplemental/units.xml. As described in Unicode Technical Standard #35 Part 6 Supplemental, Unit Preferences Data, each <unitPreferences> element contains the preferred units for its category and usage. A <unitPreferences> element contains one or more <unitPreference> elements, which define the regions (a space-separated list of region identifiers) and optionally the geq threshold for the unit preference.
This definition supersedes the definition provided in
<id type='unit' idStatus='regular'> element of the unicode_region_id Unicode locale nonterminal.
+ 1. Set _region_ to the ASCII-uppercase of _region_.
+ 1. Let _fallback_ be an empty List.
+ 1. Let _match_ be an empty List.
+ 1. For each element _unitPreference_ of _unitPreferenceElements_, do
+ 1. Assert: _unitPreference_ has an attribute regions.
+ 1. Let _regionsAttr_ be the String value of the regions attribute of _unitPreference_.
+ 1. Let _regions_ be StringSplitToList(_regionsAttr_, *" "*).
+ 1. Let _geq_ be the mathematical value of the geq attribute of _unitPreference_ if present, or 1 otherwise.
+ 1. Let _unit_ be the String value of the body of the _unitPreference_ element.
+ 1. If _regions_ contains _region_, append the Record { [[Unit]]: _unit_, [[Threshold]]: _geq_ } to _match_.
+ 1. Else if _regions_ contains *"001"*, append the Record { [[Unit]]: _unit_, [[Threshold]]: _geq_ } to _fallback_.
+ 1. If _match_ is not empty, return _match_.
+ 1. Assert: _fallback_ is not empty.
+ 1. Return _fallback_.
+ Unicode Technical Standard #35 Part 1, Unit Preferences Constraints specifies that the
<unitPreference> elements in the category and _usage_ is the usage of a <unitPreferences> element in the <unitPreference> elements in _unitPreferencesParent_.
+ 1. Return _unitPreferenceElements_.
+ 1. Else if _usage_ is not *"default"*, then
+ 1. Let _len_ be the length of _usage_.
+ 1. Let _idx_ be StringLastIndexOf(_usage_, *"-"*, _len_ - 1).
+ 1. If _idx_ is ~not-found~ or _idx_ = 0, set _usage_ to *"default"*; else set _usage_ to the substring of _usage_ from 0 to _idx_.
+ 1. Else,
+ 1. Throw a *RangeError* exception.
+ + This abstract operation implements the first two steps of the + Compute the preferred output unit + algorithm specified in + Unicode Technical Standard #35 Part 6, Supplemental, Unit Preferences. +
++ TODO: The UTS #35 algorithm includes fallbacking for regions based on + UN M.49 territory containment, + but the unit preference data does not (yet) include any other numeric regions than 001. + We'll probably need to implement that in order to be compatible with possible future CLDR updates. +
++ An ECMAScript implementation that includes the ECMA-402 Internationalization API + must implement this method as specified in the ECMA-402 specification. + If an ECMAScript implementation does not include the ECMA-402 API, + GetAmountConvertToUnit performs the following steps when called: +
+Unit conversion data is derived from CLDR file units.xml. As described in Unicode Technical Standard #35 Part 6 Supplemental, Conversion Data, each <convertUnit> element defines how to convert a source unit into a compatible baseUnit. An ECMAScript implementation must ignore all special conversions and support all conversions based on factor and/or offset, interpreting the value for each as an arithmetic expression with mathematical value operands (noting the respective defaults of 1 and 0 and the implicit presence of an identity mapping for each unit identified as the value of a baseUnit).
Unit conversion data is derived from CLDR file supplemental/units.xml. As described in Unicode Technical Standard #35 Part 6 Supplemental, Conversion Data, each <convertUnit> element defines how to convert a source unit into a compatible baseUnit. An ECMAScript implementation must ignore all special conversions and support all conversions based on factor and/or offset, interpreting the value for each as an arithmetic expression with mathematical value operands (noting the respective defaults of 1 and 0 and the implicit presence of an identity mapping for each unit identified as the value of a baseUnit).
Two units are convertible if and only if they share the same baseUnit value in CLDR. A unit that appears as a baseUnit value has an implicit identity conversion (factor 1, offset 0).
In factor and offset expressions, * multiplication binds more tightly than / division, and constants defined by <unitConstant> elements are valid operands.