alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 154 forks source link

Plural parse mistake when intl.get as nested json after version 2.3.0 #156

Closed ghost closed 3 years ago

ghost commented 3 years ago

Case

code list

// locale.json

{
  "ALBUM": {
    "HOME": "You have {num, plural, =1 {one photo.} other {# photos.}}",
    "RED_HOME": "You have {num, plural, one {one photo.} other {# photos.}}"
  }
}

<div>{intl.get("ALBUM.HOME", { num: 1 })}</div>
<div>{intl.get("ALBUM.RED_HOME", { num: 1 })}</div>

result

Reproduce Example

https://codesandbox.io/s/react-intl-universal-example-forked-6bclw?file=/src/Plural.js

Temp Solution

Don't use as below:

"You have {num, plural, one {one photo.} other {# photos.}}"

Or downgrade version to < 2.3.0, for example, 2.2.5

cwtuan commented 3 years ago

Please use this format:

{ "PHOTO": "You have {num, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}" }