【问题标题】:React-Intl: Message not formatting in SafariReact-Intl:消息未在 Safari 中格式化
【发布时间】:2020-01-19 10:16:54
【问题描述】:

我有以下翻译:

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

在 Chrome 中它显示 23 Kundenbewertungen 很好,但在 Safari 中它显示翻译字符串并引发错误

错误格式化消息:“pdp:product-title:ratings”,区域设置:“de”

无法格式化消息:“pdp:product-title:ratings”,使用消息源作为后备。

在我的 React 组件中,代码如下:

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

我完全迷失了,因为它在 Chrome 中按预期工作。我使用的语法正确吗?

【问题讨论】:

    标签: reactjs react-intl


    【解决方案1】:

    原因是 Intl.PluralRules 它在 Safari 上不可用。只需使用这个polyfill,一切都会按预期工作。

    【讨论】:

      【解决方案2】:

      这是一个更好的 polyfill,由 MDN 推荐并被 polyfill.io 使用:https://formatjs.io/docs/polyfills/intl-pluralrules/

      【讨论】:

        猜你喜欢
        • 2019-03-15
        • 2017-10-05
        • 2017-04-29
        • 2017-07-13
        • 1970-01-01
        • 1970-01-01
        • 2018-01-28
        • 2020-09-06
        • 2018-02-23
        相关资源
        最近更新 更多