formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

ICU `plural` format is ignoring offset when formatting `#` #202

Closed RoystonS closed 4 years ago

RoystonS commented 5 years ago

Which package? intl-messageformat

Describe the bug When using offset with plural, the offset is supposed to be subtracted from the value before being substituted into the # format marker, but it's not being subtracted.

To Reproduce Steps to reproduce the behavior:

Using the example from http://userguide.icu-project.org/formatparse/messages, I've created a codesandbox that illustrates the issue:

https://codesandbox.io/s/old-river-rinru

Specifically, using the format

{num_guests, plural, offset:1
  =0 {{host} does not give a party.}
  =1 {{host} invites {guest} to their party.}
  =2 {{host} invites {guest} and one other person to their party.}
  other {{host} invites {guest} and # other people to their party.}
}

with values from 0-3 gives this set of output:

The host does not give a party.
The host invites Alice to their party.
The host invites Alice and one other person to their party.
The host invites Alice and 3 other people to their party

Expected behavior The last case should read The host invites Alice and 2 other people to their party. That is, when computing the value for #, it should have had the offset subtracted from it.

The library does correctly subtract the offset when computing the plural form to choose; it's just failing to use the offset for #.

Desktop (please complete the following information):

Additional context We noticed this as we're upgrading from v2.2.0 (where this did work correctly) to v7.3.1 (where it doesn't).

longlho commented 5 years ago

Thanks for reporting! We'll take a look asap.

RoystonS commented 4 years ago

Thank you - works beautifully!