Skip to content

Conversation

@ben-allen
Copy link
Contributor

@ben-allen ben-allen commented Aug 8, 2025

This PR allows implementations to take into account potential differences between the short compact form ("5K") and long form ("5 thousand") when determining the correct plural form to use.

Fixes: #1013

This PR allows implementations to take into account potential
differences between the short compact form ("5K") and long form ("5
thousand") when determining the correct plural form to use.
@ben-allen ben-allen requested a review from ryzokuken August 8, 2025 16:36
@ben-allen
Copy link
Contributor Author

note: the potentially controversial decision here is to have PluralRuleSelect and PluralRuleSelectRange take an Intl.PluralRules object, in order to avoid having it take an additional very rarely used compactDisplay parameter.

Comment on lines 280 to 288
PluralRuleSelect (
_locale_: a language tag,
_type_: *"cardinal"* or *"ordinal"*,
_notation_: a String,
_pluralRules_: an Intl.PluralRules,
_s_: a decimal String,
): *"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, or *"other"*
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned String characterizes the plural category of _s_ according to _locale_, _type_, and _notation_.</dd>
<dd>The returned String characterizes the plural category of _s_ according to the effective locale and the internal slots of _pluralRules_: [[Type]], one of the String values *"cardinal"* or *"ordinal"*, [[Notation]], specifying the notation used, and [[CompactDisplay]], specifying whether compact notation affixes are to be displayed in short form or long form.</dd>
</dl>
Copy link
Member

Choose a reason for hiding this comment

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

Are implementations allowed to use other slots of the Intl.PluralRules instance? A significant benefit of narrowly constraining parameters for implementation-defined abstract operations is that it makes clear what details must not affect their behavior.

Copy link
Contributor Author

@ben-allen ben-allen Aug 12, 2025

Choose a reason for hiding this comment

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

The headers specify the slots of _pluralRules_ that are used. Is that sufficient to properly restrict slot usage, or is it necessary to restrict them via the parameters list?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to do so via parameters, and if those ever get too excessive I'd advocate for introducing a new specialized record type (which here would be something like a Plural Rule Selector Record { [[Type]]: *"cardinal"* or *"ordinal"*, [[Notation]]: a string, [[CompactDisplay]]: *"short"* or *"long"* }).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed an update restoring the original parameters + the _compactDisplay_ parameter.

additionally: made the assignment to _pluralRules_.[[CompactDisplay]] in the PluralRules constructor non-conditional, since (correct me if I'm wrong) there's no reason not to just let it be *"short"* when using non-compact notations.

ben-allen and others added 2 commits August 12, 2025 10:34
Co-authored-by: Richard Gibson <[email protected]>
…move conditional when setting _pluralRules_.[[CompactDisplay]]
@ben-allen ben-allen force-pushed the 1013-PluralRules-compactDisplay branch from 3357fc0 to c85b34b Compare August 12, 2025 19:10
Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

👍

@ben-allen ben-allen added has consensus Has consensus from TC39-TG2 needs consensus labels Aug 14, 2025
@sffc
Copy link
Contributor

sffc commented Aug 15, 2025

@sffc sffc moved this from Priority Issues to Previously Discussed in ECMA-402 Meeting Topics Sep 9, 2025
@ben-allen ben-allen added has consensus (TG1) Has consensus from TC39-TG1 and removed needs consensus labels Oct 9, 2025
@FrankYFTang
Copy link
Contributor

This is approved in TC39 september-22 meeting
See the PR for the 2025-9 meeting note tc39/notes#384

@FrankYFTang
Copy link
Contributor

Please merge it asap

@FrankYFTang
Copy link
Contributor

FrankYFTang added a commit to FrankYFTang/test262 that referenced this pull request Oct 15, 2025
PR 1019 is approved by TG1 in 2025-9 meeting 
and should be merged soon. 
tc39/ecma402#1019
@FrankYFTang
Copy link
Contributor

found an issue about this PR and report in #1031

hubot pushed a commit to v8/v8 that referenced this pull request Oct 17, 2025
To sync the implementation for the following 2 PRs

tc39/ecma402#989
and
tc39/ecma402#1019

PR 989, adding "notation", is already merged into ECMA402 in
https://tc39.es/ecma402/#sec-intl.pluralrules
https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.select
and
https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions

PR 1019 passed TC39 in 2025-Sept meeting and should be mereged into
ECMA402 soon.

Move some shared enum and code from anonymous namespace into Intl
inside JSNumberFormat so code inside JSPluralRules can just reuse them.

Also removed two function declaration inside Intl which no longer exist.

Bug: 452130289
Change-Id: I47a68339802eaf8df31ccf99fd53a59c5c4f5370
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7047379
Commit-Queue: Frank Tang <[email protected]>
Reviewed-by: Olivier Flückiger <[email protected]>
Cr-Commit-Position: refs/heads/main@{#103187}
@ben-allen ben-allen merged commit 33893b3 into tc39:main Oct 22, 2025
2 checks passed
eemeli added a commit to tc39/proposal-intl-keep-trailing-zeros that referenced this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has consensus (TG1) Has consensus from TC39-TG1 has consensus Has consensus from TC39-TG2 normative

Projects

Status: Previously Discussed

Development

Successfully merging this pull request may close these issues.

Add "compactDisplay" option to Intl.PluralRules

5 participants