Skip to content

Commit c801f42

Browse files
committed
Normative: Align RegionPreference and CanonicalUnicodeSubdivision with UTS 35
Changes in `CanonicalUnicodeSubdivision`: - Don't canonicalize region subtags to replace aliases. - Only allow valid regular region codes using validity data defined in UTS 35. Changes in `RegionPreference`: - Return the first region which can be matched, using the following preference order: 1. Region override Unicode extension key `rg`. 2. Region subtag in locale. 3. Subdivision Unicode extenion key `sd`. 4. Region subtag added through likely subtags. 5. Fallback to region code `001`. Fixes tc39#1058
1 parent 4781b0d commit c801f42

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

spec/locale.html

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -575,38 +575,40 @@ <h1>
575575
): a String or *undefined*
576576
</h1>
577577
<dl class="header">
578+
<dt>description</dt>
579+
<dd>The following algorithm refers to Region validity data specified in <a href="https://unicode.org/reports/tr35/#unicode_region_subtag_validity">Unicode Technical Standard #35 Part 1 Core, Language Identifier Field Definitions</a>.</dd>
578580
</dl>
579581
<emu-alg>
580582
1. Let _subdivision_ be UnicodeExtensionValue(_locale_, _key_).
581583
1. If _subdivision_ is ~empty~, return *undefined*.
582584
1. If _subdivision_ cannot be matched by the `unicode_subdivision_id` Unicode locale nonterminal, return *undefined*.
583585
1. Let _region_ be the longest prefix of _subdivision_ matched by the `unicode_region_subtag` Unicode locale nonterminal.
584-
1. Let _regionLocale_ be the string-concatenation of *"und-"* and _region_.
585-
1. Set _regionLocale_ to CanonicalizeUnicodeLocaleId(_regionLocale_).
586-
1. Return GetLocaleRegion(_regionLocale_).
586+
1. Set _region_ to the ASCII-uppercase of _region_.
587+
1. If _region_ is not a valid regular region code, return *undefined*.
588+
1. Return _region_.
587589
</emu-alg>
588590
</emu-clause>
589591

590592
<emu-clause id="sec-regionpreference" type="abstract operation">
591593
<h1>
592594
RegionPreference (
593595
_locale_: a Unicode canonicalized locale identifier,
594-
): a Record with fields [[Region]] (a String) and [[RegionOverride]] (a String or *undefined*)
596+
): a String
595597
</h1>
596598
<dl class="header">
597599
</dl>
598600
<emu-alg>
599-
1. Let _region_ be GetLocaleRegion(_locale_).
600-
1. If _region_ is *undefined*, then
601-
1. Set _region_ to CanonicalUnicodeSubdivision(_locale_, *"sd"*).
602-
1. If _region_ is *undefined*, then
603-
1. Let _maximal_ be the result of the <a href="https://unicode.org/reports/tr35/#Likely_Subtags">Add Likely Subtags</a> algorithm applied to _locale_. If an error is signaled, set _maximal_ to _locale_.
604-
1. Set _maximal_ to CanonicalizeUnicodeLocaleId(_maximal_).
605-
1. Set _region_ to GetLocaleRegion(_maximal_).
606-
1. If _region_ is *undefined*, then
607-
1. Set _region_ to *"001"*.
608-
1. Let _regionOverride_ be CanonicalUnicodeSubdivision(_locale_, *"rg"*).
609-
1. Return { [[Region]]: _region_, [[RegionOverride]]: _regionOverride_ }.
601+
1. Let _region_ be CanonicalUnicodeSubdivision(_locale_, *"rg"*).
602+
1. If _region_ is not *undefined*, return _region_.
603+
1. Set _region_ to GetLocaleRegion(_locale_).
604+
1. If _region_ is not *undefined*, return _region_.
605+
1. Set _region_ to CanonicalUnicodeSubdivision(_locale_, *"sd"*).
606+
1. If _region_ is not *undefined*, return _region_.
607+
1. Let _maximal_ be the result of the <a href="https://unicode.org/reports/tr35/#Likely_Subtags">Add Likely Subtags</a> algorithm applied to _locale_. If an error is signaled, set _maximal_ to _locale_.
608+
1. Set _maximal_ to CanonicalizeUnicodeLocaleId(_maximal_).
609+
1. Set _region_ to GetLocaleRegion(_maximal_).
610+
1. If _region_ is not *undefined*, return _region_.
611+
1. Return *"001"*.
610612
</emu-alg>
611613
</emu-clause>
612614

@@ -623,14 +625,8 @@ <h1>
623625
<emu-alg>
624626
1. If _loc_.[[Calendar]] is not *undefined*, then
625627
1. Return CreateArrayFromList(« _loc_.[[Calendar]] »).
626-
1. Let _preference_ be RegionPreference(_loc_.[[Locale]]).
627-
1. Let _region_ be _preference_.[[Region]].
628-
1. Let _regionOverride_ be _preference_.[[RegionOverride]].
629-
1. If _regionOverride_ is not *undefined* and calendar preference data for _regionOverride_ are available, then
630-
1. Let _lookupRegion_ be _regionOverride_.
631-
1. Else,
632-
1. Let _lookupRegion_ be _region_.
633-
1. Let _list_ be a List of unique calendar types in canonical form (<emu-xref href="#sec-calendar-types"></emu-xref>), sorted in descending preference of those in common use for date and time formatting in _lookupRegion_. The list is empty if no calendar preference data for _lookupRegion_ is available.
628+
1. Let _region_ be RegionPreference(_loc_.[[Locale]]).
629+
1. Let _list_ be a List of unique calendar types in canonical form (<emu-xref href="#sec-calendar-types"></emu-xref>), sorted in descending preference of those in common use for date and time formatting in _region_. The list is empty if no calendar preference data for _region_ is available.
634630
1. If _list_ is empty, set _list_ to « *"gregory"* ».
635631
1. Return CreateArrayFromList(_list_).
636632
</emu-alg>
@@ -678,14 +674,8 @@ <h1>
678674
<emu-alg>
679675
1. If _loc_.[[HourCycle]] is not *undefined*, then
680676
1. Return CreateArrayFromList(« _loc_.[[HourCycle]] »).
681-
1. Let _preference_ be RegionPreference(_loc_.[[Locale]]).
682-
1. Let _region_ be _preference_.[[Region]].
683-
1. Let _regionOverride_ be _preference_.[[RegionOverride]].
684-
1. If _regionOverride_ is not *undefined* and time data for _regionOverride_ are available, then
685-
1. Let _lookupRegion_ be _regionOverride_.
686-
1. Else,
687-
1. Let _lookupRegion_ be _region_.
688-
1. Let _list_ be a List of unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format (*"h11"*, *"h12"*) or the 24-hour format (*"h23"*, *"h24"*), sorted in descending preference of those in common use for date and time formatting in _lookupRegion_. The list is empty if no time data for _lookupRegion_ is available.
677+
1. Let _region_ be RegionPreference(_loc_.[[Locale]]).
678+
1. Let _list_ be a List of unique hour cycle identifiers, which must be lower case String values indicating either the 12-hour format (*"h11"*, *"h12"*) or the 24-hour format (*"h23"*, *"h24"*), sorted in descending preference of those in common use for date and time formatting in _region_. The list is empty if no time data for _region_ is available.
689679
1. If _list_ is empty, set _list_ to « *"h23"* ».
690680
1. Return CreateArrayFromList(_list_).
691681
</emu-alg>

0 commit comments

Comments
 (0)