Skip to content

fix(@formatjs/intl-relativetimeformat): fall back to the other pattern for missing plural categories - #7633

Merged
longlho merged 2 commits into
formatjs:mainfrom
ybai08:fix/relativetimeformat-plural-fallback
Oct 19, 2026
Merged

longlho merged 2 commits into
formatjs:mainfrom
ybai08:fix/relativetimeformat-plural-fallback

Conversation

@ybai08

@ybai08 ybai08 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

PartitionRelativeTimePattern looks up the pattern for the selected plural category with po[pr] and passes it straight to MakePartsList. CLDR only guarantees the other count pattern, so when a locale's data has no pattern for the selected category, pattern is undefined and format() / formatToParts() throw:

import '@formatjs/intl-pluralrules/polyfill-force.js'
import '@formatjs/intl-pluralrules/locale-data/gsw.js'
import '@formatjs/intl-relativetimeformat/polyfill-force.js'
import '@formatjs/intl-relativetimeformat/locale-data/gsw.js'

new Intl.RelativeTimeFormat('gsw').format(-1, 'second')
// TypeError: Cannot read properties of undefined (reading 'indexOf')
//   at PartitionPattern ... at MakePartsList ... at PartitionRelativeTimePattern

This happens in two cases:

  • The locale has no counted relative-time patterns of its own, so CLDR resolves them from root, which only has other (+{0} s, -{0} d, ...). Examples: gsw, haw, ceb, kw, gv, ckb.
  • The locale has patterns for some units but not all of them. For example, fy and kl have no quarter patterns.

In both cases the locale's plural rules still select one / two / few, so there is no pattern to use.

With this change, the other pattern is used when the selected category is missing. That is the CLDR plural fallback, and it gives the same output as ICU. Node 26 (ICU 78) gives -1 s for new Intl.RelativeTimeFormat('gsw').format(-1, 'second').

How often it happens with the published 12.3.15 packages:

  • With polyfilled Intl.PluralRules and both polyfills' locale data loaded for each of the 216 locales the two packages share, 82 locales threw on ordinary inputs such as format(-1, 'second') or format(1, 'quarter'). With this change, none do.
  • With native Intl.PluralRules, which is the setup polyfill.js gives you on an engine that lacks one of these locales, 276 of 766 locale-data files threw.
  • Compared with native Intl.RelativeTimeFormat on Node 26 across 662 locales, 3 styles, 2 numeric values, 8 units and 13 values: mismatches dropped from 25,641 in 188 locales to 10,010 in 23 locales. All of the remaining 23 are script or region variants that ICU resolves differently (az-Arab, en-Dsrt, mn-Mong, ...). None of them throw.

Test: I added gsw to TEST_LOCALES and a test in tests/index.test.ts for format(-1, 'second'), format(1, 'day') and formatToParts(1, 'hour'). The test fails on main with the TypeError above and passes with the fix.

Checks run locally (macOS arm64, Bazel 9.3.0):

  • bazel test //packages/intl-relativetimeformat/... //packages/ecma402-abstract/...: 30 of 30 pass, including //packages/intl-relativetimeformat:test262
  • oxfmt, oxlint, ast-grep scan and buildifier on the changed files: clean
  • gazelle: no changes

Not run: the full bazel test //..., and scripts/generate_dist_packages.sh, which fails under macOS's bash 3.2 before it does anything. This PR changes no package list.

ybai08 and others added 2 commits October 17, 2026 08:12
…n for missing plural categories

CLDR only guarantees the `other` count pattern. Locales whose relative-time
patterns come from root (gsw, haw, ceb, kw, ...) or that lack some counts
(fy and kl for quarters) have no `one`/`two`/`few` pattern, but their plural
rules still select those categories. format() and formatToParts() then
passed undefined to PartitionPattern and threw a TypeError, e.g.
new Intl.RelativeTimeFormat('gsw').format(-1, 'second').

Use the `other` pattern when the selected category is missing, which is the
CLDR plural fallback and matches ICU ("-1 s").
@longlho
longlho merged commit 72d1c94 into formatjs:main Oct 19, 2026
14 checks passed
longlho pushed a commit that referenced this pull request Oct 19, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>icu_messageformat: 0.1.1</summary>

##
[0.1.1](https://github.com/formatjs/formatjs/compare/[email protected][email protected])
(2026-10-19)


### Bug Fixes

* align stand-alone weekday names across TypeScript and Rust
([#7634](#7634))
([54ab77d](54ab77d))
</details>

<details><summary>py_intl: 0.4.0</summary>

##
[0.4.0](https://github.com/formatjs/formatjs/compare/[email protected][email protected])
(2026-10-19)


### Features

* **intl_python:** add reusable message catalogs
([#7645](#7645))
([75fd5b9](75fd5b9))


### Bug Fixes

* align stand-alone weekday names across TypeScript and Rust
([#7634](#7634))
([54ab77d](54ab77d))
</details>

<details><summary>formatjs_cli: 1.8.2</summary>

##
[1.8.2](formatjs_cli_v1.8.1...formatjs_cli_v1.8.2)
(2026-10-19)


### Bug Fixes

* **deps:** update oxc to 0.153
([#7608](#7608))
([f6c95f8](f6c95f8))
* **deps:** update ruff to v0.17.0
([#7629](#7629))
([cb56c4b](cb56c4b))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * formatjs_icu_messageformat_parser bumped from 1.1.0 to 1.1.1
</details>

<details><summary>formatjs_icu_messageformat: 0.3.1</summary>

##
[0.3.1](formatjs_icu_messageformat_v0.3.0...formatjs_icu_messageformat_v0.3.1)
(2026-10-19)


### Bug Fixes

* align stand-alone weekday names across TypeScript and Rust
([#7634](#7634))
([54ab77d](54ab77d))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * formatjs_icu_messageformat_parser bumped from 1.1.0 to 1.1.1
</details>

<details><summary>formatjs_icu_messageformat_parser: 1.1.1</summary>

##
[1.1.1](formatjs_icu_messageformat_parser_v1.1.0...formatjs_icu_messageformat_parser_v1.1.1)
(2026-10-19)


### Bug Fixes

* **@formatjs/icu-messageformat-parser:** allow shared date/time
arguments ([#7616](#7616))
([2802fe7](2802fe7))
</details>

<details><summary>formatjs_intl: 2.2.1</summary>

##
[2.2.1](formatjs_intl_v2.2.0...formatjs_intl_v2.2.1)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * formatjs_icu_messageformat bumped from 0.3.0 to 0.3.1
    * formatjs_intl_macros bumped from 1.1.0 to 1.1.1
</details>

<details><summary>formatjs_intl_macros: 1.1.1</summary>

##
[1.1.1](formatjs_intl_macros_v1.1.0...formatjs_intl_macros_v1.1.1)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * formatjs_icu_messageformat_parser bumped from 1.1.0 to 1.1.1
</details>

<details><summary>@formatjs/cli: 6.16.35</summary>

##
[6.16.35](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * optionalDependencies
    * @formatjs/cli-native-darwin-arm64 bumped to 1.1.29
    * @formatjs/cli-native-linux-arm64 bumped to 1.2.29
    * @formatjs/cli-native-linux-arm64-musl bumped to 1.0.27
    * @formatjs/cli-native-linux-x64 bumped to 1.1.29
    * @formatjs/cli-native-linux-x64-musl bumped to 1.0.27
    * @formatjs/cli-native-win32-x64 bumped to 1.1.30
</details>

<details><summary>@formatjs/cli-lib: 10.0.11</summary>

##
[10.0.11](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
  * optionalDependencies
    * @formatjs/cli-native-darwin-arm64 bumped to 1.1.29
    * @formatjs/cli-native-linux-arm64 bumped to 1.2.29
    * @formatjs/cli-native-linux-arm64-musl bumped to 1.0.27
    * @formatjs/cli-native-linux-x64 bumped to 1.1.29
    * @formatjs/cli-native-linux-x64-musl bumped to 1.0.27
    * @formatjs/cli-native-win32-x64 bumped to 1.1.30
</details>

<details><summary>@formatjs/cli-native-darwin-arm64: 1.1.29</summary>

##
[1.1.29](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)
</details>

<details><summary>@formatjs/cli-native-linux-arm64: 1.2.29</summary>

##
[1.2.29](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)
</details>

<details><summary>@formatjs/cli-native-linux-arm64-musl:
1.0.27</summary>

##
[1.0.27](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* **deps:** update oxc to 0.153
([#7608](#7608))
([f6c95f8](f6c95f8))
</details>

<details><summary>@formatjs/cli-native-linux-x64: 1.1.29</summary>

##
[1.1.29](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)
</details>

<details><summary>@formatjs/cli-native-linux-x64-musl: 1.0.27</summary>

##
[1.0.27](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* **deps:** update oxc to 0.153
([#7608](#7608))
([f6c95f8](f6c95f8))
</details>

<details><summary>@formatjs/cli-native-win32-x64: 1.1.30</summary>

##
[1.1.30](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)
</details>

<details><summary>@formatjs/editor: 1.7.3</summary>

##
[1.7.3](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
</details>

<details><summary>@formatjs/icu-messageformat-parser: 3.5.22</summary>

##
[3.5.22](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* **@formatjs/icu-messageformat-parser:** allow shared date/time
arguments ([#7616](#7616))
([2802fe7](2802fe7))
</details>

<details><summary>@formatjs/intl: 6.1.4</summary>

##
[6.1.4](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * intl-messageformat bumped to 12.1.4
</details>

<details><summary>@formatjs/intl-datetimeformat: 7.8.2</summary>

##
[7.8.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* align stand-alone weekday names across TypeScript and Rust
([#7634](#7634))
([54ab77d](54ab77d))
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-buddhist:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-chinese:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-coptic:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-dangi:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-ethioaa:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-ethiopic:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-hebrew:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-indian:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-islamic-civil:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-islamic-tbla:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>


<details><summary>@formatjs/intl-datetimeformat-calendar-islamic-umalqura:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-japanese:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-persian:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-datetimeformat-calendar-roc:
1.1.2</summary>

##
[1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * peerDependencies
    * @formatjs/intl-datetimeformat bumped to 7.8.2
</details>

<details><summary>@formatjs/intl-pluralrules: 6.3.16</summary>

##
[6.3.16](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* **@formatjs/intl-pluralrules:** keep fraction digits when selecting
([#7619](#7619))
([1f5f78d](1f5f78d))
</details>

<details><summary>@formatjs/intl-relativetimeformat: 12.3.16</summary>

##
[12.3.16](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Bug Fixes

* **@formatjs/intl-relativetimeformat:** fall back to the other pattern
for missing plural categories
([#7633](#7633))
([72d1c94](72d1c94))
</details>

<details><summary>@formatjs/svelte-intl: 2.1.4</summary>

##
[2.1.4](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/intl bumped to 6.1.4
</details>

<details><summary>@formatjs/ts-transformer: 4.5.1</summary>

##
[4.5.1](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
</details>

<details><summary>@formatjs/unplugin: 1.2.14</summary>

##
[1.2.14](https://github.com/formatjs/formatjs/compare/@formatjs/[email protected]...@formatjs/[email protected])
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/ts-transformer bumped to 4.5.1
</details>

<details><summary>babel-plugin-formatjs: 13.0.8</summary>

##
[13.0.8](https://github.com/formatjs/formatjs/compare/[email protected]@13.0.8)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/ts-transformer bumped to 4.5.1
</details>

<details><summary>eslint-plugin-formatjs: 8.1.2</summary>

##
[8.1.2](https://github.com/formatjs/formatjs/compare/[email protected]@8.1.2)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/ts-transformer bumped to 4.5.1
</details>

<details><summary>intl-messageformat: 12.1.4</summary>

##
[12.1.4](https://github.com/formatjs/formatjs/compare/[email protected]@12.1.4)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
</details>

<details><summary>react-intl: 12.1.5</summary>

##
[12.1.5](https://github.com/formatjs/formatjs/compare/[email protected]@12.1.5)
(2026-10-19)


### Bug Fixes

* **deps:** update formatjs monorepo
([#7599](#7599))
([0a5bedb](0a5bedb))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/intl bumped to 6.1.4
    * intl-messageformat bumped to 12.1.4
</details>

<details><summary>vue-intl: 8.1.4</summary>

##
[8.1.4](https://github.com/formatjs/formatjs/compare/[email protected]@8.1.4)
(2026-10-19)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @formatjs/icu-messageformat-parser bumped to 3.5.22
    * @formatjs/intl bumped to 6.1.4
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants