Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Intl: Message not formatting in Safari

I have the following translation:

{count, number} {count, plural, one {Kundenbewertung} other {Kundenbewertungen}}

In Chrome it displays 23 Kundenbewertungen just fine but in Safari it displays the translation string and throws the error

Error formatting message: "pdp:product-title:ratings" for locale: "de"

Cannot format message: "pdp:product-title:ratings", using message source as fallback.

In my React Component the code is the following:

<FormattedMessage
  id="pdp:product-title:ratings"
  values={{ count: product.metadata.rating.count }}
/>

I am totally lost, because it works as expected in Chrome. Am I using the syntax correctly?

like image 956
mxmtsk Avatar asked Sep 18 '19 12:09

mxmtsk


2 Answers

Reason is that Intl.PluralRules it not available on Safari. Just use this polyfill and everything should work as expected.

like image 149
Yuriy Yakym Avatar answered Sep 19 '22 14:09

Yuriy Yakym


This is a much better polyfill, recommended by MDN and used by polyfill.io: https://formatjs.io/docs/polyfills/intl-pluralrules/

like image 39
Janne Annala Avatar answered Sep 20 '22 14:09

Janne Annala