close
Skip to content

Normative: Add Intl.Locale.prototype.variants#960

Merged
gibson042 merged 3 commits into
tc39:mainfrom
gibson042:gh-900-locale-getvariants
May 29, 2025
Merged

Normative: Add Intl.Locale.prototype.variants#960
gibson042 merged 3 commits into
tc39:mainfrom
gibson042:gh-900-locale-getvariants

Conversation

@gibson042
Copy link
Copy Markdown
Member

@gibson042 gibson042 commented Feb 14, 2025

Fixes #900

test262 PR: tc39/test262#4474

Comment thread spec/locale.html Outdated
1. Perform ? RequireInternalSlot(_loc_, [[InitializedLocale]]).
1. Let _variantsString_ be GetLocaleVariants(_loc_.[[Locale]]).
1. Let _variantsList_ be StringSplitToList(_variantsString_, *"-"*).
1. Return CreateArrayFromList(_variantsList_).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might benefit from a note, but nothing more—alphabetization is already required by use of CanonicalizeUnicodeLocaleId in the Intl.Locale constructor.

@FrankYFTang
Copy link
Copy Markdown
Contributor

If we do this, then how about setting variants in option bag them?

@gibson042
Copy link
Copy Markdown
Member Author

If we do this, then how about setting variants in option bag them?

Good question, and I think the answer is "yes". This also interacts with the design question about representing variants as an array of strings or as a single dash-separated string, and I'm increasingly inclined towards the latter.

@sffc
Copy link
Copy Markdown
Contributor

sffc commented Mar 10, 2025

@sffc
Copy link
Copy Markdown
Contributor

sffc commented Apr 3, 2025

TG2 discussion, focused on the motivation: https://github.com/tc39/ecma402/blob/main/meetings/notes-2025-04-03.md#normative-add-localeprototypegetvariants-960

Comment thread spec/locale.html Outdated
@gibson042
Copy link
Copy Markdown
Member Author

In accord with #960 (comment) and TG2 discussion, this will be exposed as a string-returning variants getter to align with the other subtag-based properties (language, baseName, script, region, calendar, etc.).

@gibson042 gibson042 force-pushed the gh-900-locale-getvariants branch from c001a65 to a606142 Compare May 8, 2025 20:21
gibson042 added a commit to gibson042/test262 that referenced this pull request May 8, 2025
@gibson042 gibson042 changed the title Normative: Add Locale.prototype.getVariants Normative: Add Intl.Locale.prototype.getVariants May 9, 2025
@gibson042 gibson042 changed the title Normative: Add Intl.Locale.prototype.getVariants Normative: Add Intl.Locale.prototype.variants May 9, 2025
@ryzokuken ryzokuken added has consensus Has consensus from TC39-TG2 has tests and removed needs tests needs review labels May 13, 2025
@gibson042
Copy link
Copy Markdown
Member Author

This reached consensus in TC39 plenary.

@gibson042 gibson042 merged commit e8c995a into tc39:main May 29, 2025
2 checks passed
gibson042 added a commit to gibson042/test262 that referenced this pull request May 29, 2025
Comment thread spec/locale.html
1. Let _variants_ be GetLocaleVariants(_baseName_).
1. Let _variants_ be ? GetOption(_options_, *"variants"*, ~string~, ~empty~, GetLocaleVariants(_baseName_)).
1. If _variants_ is not *undefined*, then
1. If _variants_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode_variant_subtag matches a single variant subtag. That means new Intl.Locale("kl-tunumiit-kleinsch") will now always throw a RangeError. Probably needs StringSplitToList(variants, "-") and then check unicode_variant_subtag on all elements of the returned List.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, nice catch. Fix: #1007.

gibson042 added a commit to gibson042/ecma402 that referenced this pull request May 30, 2025
Ms2ger pushed a commit to gibson042/test262 that referenced this pull request Jun 4, 2025
Ms2ger pushed a commit to tc39/test262 that referenced this pull request Jun 4, 2025
@sffc
Copy link
Copy Markdown
Contributor

sffc commented Jun 14, 2025

webkit-commit-queue pushed a commit to sosukesuzuki/WebKit that referenced this pull request Jun 21, 2025
https://bugs.webkit.org/show_bug.cgi?id=294755

Reviewed by Yusuke Suzuki.

tc39/ecma402#960 added `Intl.Locale.prototype.variants`
to the ECMAScript specification. The test262 test suite has also been updated [1].

This patch implements `Intl.Locale.prototype.variants` for JSC.

[1]: tc39/test262#4474

* JSTests/stress/intl-locale-prototype-variants.js: Added.
(shouldBe):
(shouldThrow):
* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/CommonIdentifiers.h:
* Source/JavaScriptCore/runtime/IntlLocale.cpp:
(JSC::LocaleIDBuilder::overrideLanguageScriptRegionVariants):
(JSC::IntlLocale::initializeLocale):
(JSC::IntlLocale::variants):
(JSC::LocaleIDBuilder::overrideLanguageScriptRegion): Deleted.
* Source/JavaScriptCore/runtime/IntlLocale.h:
* Source/JavaScriptCore/runtime/IntlLocalePrototype.cpp:
(JSC::JSC_DEFINE_CUSTOM_GETTER):

Canonical link: https://commits.webkit.org/296467@main
@sffc sffc moved this from Priority Issues to Previously Discussed in ECMA-402 Meeting Topics Jul 16, 2025
hubot pushed a commit to v8/v8 that referenced this pull request Oct 18, 2025
https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants

Added to the spec by tc39/ecma402#960
Test code added in tc39/test262#4474
feature https://chromestatus.com/feature/4709921706868736
I2P https://groups.google.com/a/chromium.org/g/blink-dev/c/NCT4pPJ_Uz8/m/G62K-m6CAgAJ

Bug: 450083673
Change-Id: I49a4af9f9e75a18efb3b67f546f971d4c24e0bb0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7018878
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Olivier Flückiger <olivf@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#103188}
hubot pushed a commit to v8/v8 that referenced this pull request Oct 21, 2025
https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants

Added to the spec by tc39/ecma402#960
Test code added in tc39/test262#4474
feature https://chromestatus.com/feature/4709921706868736
I4DT https://groups.google.com/a/chromium.org/g/blink-dev/c/i6QEHcH_fiI/m/4xUyZbSvAAAJ

Bug: 450083673
Change-Id: I987b3066726323550d098222e50da999c145495c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7064530
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Rezvan Mahdavi Hezaveh <rezvan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#103233}
@sffc
Copy link
Copy Markdown
Contributor

sffc commented Nov 6, 2025

graphite-app Bot pushed a commit to formatjs/formatjs that referenced this pull request Jan 15, 2026
### TL;DR

Added the `variants` property to `Intl.Locale` and improved documentation for `CanonicalizeLocaleList`.

### What changed?

- Added the `variants` getter to the `Intl.Locale` class that returns variant subtags joined with hyphens in alphabetical order
- Added detection for the `variants` property in the `shouldPolyfill` function
- Added comprehensive tests for the new `variants` property with various locale scenarios
- Enhanced documentation in `intl-getcanonicallocales` with ECMA-402 spec references for better clarity

### How to test?

- Run the new test cases that verify the `variants` property works correctly:
  - Returns `undefined` for locales without variants
  - Returns the variant string for locales with a single variant
  - Returns hyphen-joined variants in alphabetical order for locales with multiple variants
  - Handles various locale formats with scripts, extensions, and numeric variants

### Why make this change?

This change implements the `variants` property that was added to ECMA-402 via PR #960 to align with other subtag accessors. The property provides access to the variant subtags of a locale, which was previously missing from the implementation. This brings the polyfill in line with the latest ECMA-402 specification.

References:
- https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants
- tc39/ecma402#960
- tc39/ecma402#900
hubot pushed a commit to v8/v8 that referenced this pull request Apr 9, 2026
https://tc39.es/ecma402/#sec-Intl.Locale.prototype.variants

Added to the spec by tc39/ecma402#960
Test code added in tc39/test262#4474
feature https://chromestatus.com/feature/4709921706868736
I4DT https://groups.google.com/a/chromium.org/g/blink-dev/c/i6QEHcH_fiI/m/4xUyZbSvAAAJ
I2S https://groups.google.com/a/chromium.org/g/blink-dev/c/-IH8qyT_7bQ/m/K8ymVPNvBQAJ

API Owner LGTMs: chrishtr@, foolip@, miketaylr@

Bug: 450083673
Change-Id: I2623f0fb28863dd8c3f31eeade19ecf5015c33d5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7108520
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#106371}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: locale Component: locale identifiers enhancement has consensus Has consensus from TC39-TG2 has tests needs consensus normative

Projects

Status: Previously Discussed

Development

Successfully merging this pull request may close these issues.

Why is there no Intl.Locale.prototype.variants?

6 participants