Skip to content

feat(@formatjs/intl-pluralrules): support selectRange - #5913

Closed
longlho wants to merge 1 commit into
mainfrom
01-14-feat_formatjs_intl-pluralrules_support_selectrange
Closed

longlho wants to merge 1 commit into
mainfrom
01-14-feat_formatjs_intl-pluralrules_support_selectrange

Conversation

@longlho

@longlho longlho commented Jan 15, 2026 •

Copy link
Copy Markdown
Member

TL;DR

Add selectRange method to Intl.PluralRules to support plural forms for number ranges.

What changed?

  • Implemented the selectRange(start, end) method for Intl.PluralRules according to the ECMA-402 specification
  • Added support for CLDR plural range data to determine the correct plural form for ranges
  • Created new abstract operations ResolvePluralInternal and ResolvePluralRange
  • Added ICU4J conformance tests to validate the implementation behavior
  • Enhanced type definitions to support plural ranges data
  • Updated CLDR data extraction to include plural range rules

How to test?

  • Run the ICU4J conformance tests to verify behavior matches the reference implementation
  • Test with different locales that have distinct plural range rules:
    const prEn = new Intl.PluralRules('en');
    prEn.selectRange(1, 2); // "other" (English: "1-2 items")
    prEn.selectRange(1, 1); // "one" (same value: "1 item")
    
    const prFr = new Intl.PluralRules('fr');
    prFr.selectRange(0, 1); // "one" (French: "0-1 vue")
    prFr.selectRange(1, 2); // "other" (French: "1-2 vues")
  • Verify BigInt support works correctly (unlike Chrome's native implementation)

Why make this change?

The selectRange method is part of the ECMA-402 specification but was missing from our implementation. This method is essential for correctly formatting phrases with number ranges in different languages, where plural rules for ranges can be complex. For example, in English "1-2 items" uses the "other" form, while in French "0-1 vue" uses the "one" form.

This implementation follows the spec by returning the start category when the formatted strings are identical, and otherwise consulting locale-specific plural range data from CLDR. The ICU4J conformance tests confirm our implementation matches the reference behavior.

longlho commented Jan 15, 2026 •

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • main - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@graphite-app
graphite-app Bot changed the base branch from 01-14-feat_formatjs_intl-pluralrules_remove_make-plural-compiler_add_support_for_huge_numbers to graphite-base/5913 January 15, 2026 04:23
@longlho
longlho force-pushed the graphite-base/5913 branch from e933aa8 to bed7271 Compare January 15, 2026 04:23
@longlho
longlho force-pushed the 01-14-feat_formatjs_intl-pluralrules_support_selectrange branch from 8d69cd6 to b857c77 Compare January 15, 2026 04:23
@graphite-app
graphite-app Bot changed the base branch from graphite-base/5913 to main January 15, 2026 04:24
@graphite-app

graphite-app Bot commented Jan 15, 2026 •

Copy link
Copy Markdown

Merge activity

  • Jan 15, 4:24 AM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.
  • Jan 15, 5:30 AM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 15, 5:30 AM UTC: CI is running for this pull request on a draft pull request (#5915) due to your merge queue CI optimization settings.
  • Jan 15, 5:46 AM UTC: Merged by the Graphite merge queue via draft PR: #5915.

@longlho
longlho force-pushed the 01-14-feat_formatjs_intl-pluralrules_support_selectrange branch from b857c77 to bf702c4 Compare January 15, 2026 04:41
graphite-app Bot pushed a commit that referenced this pull request Jan 15, 2026
### TL;DR

Add `selectRange` method to `Intl.PluralRules` to support plural forms for number ranges.

### What changed?

- Implemented the `selectRange(start, end)` method for `Intl.PluralRules` according to the ECMA-402 specification
- Added support for CLDR plural range data to determine the correct plural form for ranges
- Created new abstract operations `ResolvePluralInternal` and `ResolvePluralRange`
- Added ICU4J conformance tests to validate the implementation behavior
- Enhanced type definitions to support plural ranges data
- Updated CLDR data extraction to include plural range rules

### How to test?

- Run the ICU4J conformance tests to verify behavior matches the reference implementation
- Test with different locales that have distinct plural range rules:
  ```js
  const prEn = new Intl.PluralRules('en');
  prEn.selectRange(1, 2); // "other" (English: "1-2 items")
  prEn.selectRange(1, 1); // "one" (same value: "1 item")

  const prFr = new Intl.PluralRules('fr');
  prFr.selectRange(0, 1); // "one" (French: "0-1 vue")
  prFr.selectRange(1, 2); // "other" (French: "1-2 vues")
  ```
- Verify BigInt support works correctly (unlike Chrome's native implementation)

### Why make this change?

The `selectRange` method is part of the ECMA-402 specification but was missing from our implementation. This method is essential for correctly formatting phrases with number ranges in different languages, where plural rules for ranges can be complex. For example, in English "1-2 items" uses the "other" form, while in French "0-1 vue" uses the "one" form.

This implementation follows the spec by returning the start category when the formatted strings are identical, and otherwise consulting locale-specific plural range data from CLDR. The ICU4J conformance tests confirm our implementation matches the reference behavior.
@graphite-app graphite-app Bot closed this Jan 15, 2026
@graphite-app
graphite-app Bot deleted the 01-14-feat_formatjs_intl-pluralrules_support_selectrange branch January 15, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant