【问题标题】:i18next interpolation in Russian language俄语 i18next 插值
【发布时间】:2021-10-04 16:44:13
【问题描述】:

我正在尝试在我的 React 应用程序中使用 i18next 和插值

这是 React 代码中的示例

 {i18n.t('hours', {ns:'namespace', count: 100})}
        <Trans i18nKey='hours' ns='namespace' count={10}/>
        {t('hours', {count: 1})}

这是我的“namespace.json”

  "hours_one": "час",
  "hours_few": "часа",
  "hours_many": "часов"
  "hours": "часы {{count}}"

这是我的输出

часы 100
часы {{count}}
часы 1

如您所见,不起作用。我不知道为什么。 有人可以帮助我了解我做错了什么吗?

配置

const resources = {
  ru: {
    namespace: namespaceRU
  }
};
i18n
  .use(Backend)
  .use(LanguageDetector)
  .use(initReactI18next)

  .init({
    resources,
    fallbackLng: 'ru',
    debug: true,
    supportedLngs: ['ru'],
    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    },
    react: {
      useSuspense: false
    },
  });

【问题讨论】:

    标签: string-interpolation i18next


    【解决方案1】:

    您需要更改 Trans 组件中的两件事:

    1. t 传递给Trans
    2. 使用values 属性来传递count
    <Trans t={t} i18nKey='hours' ns='namespace' values={{count: 10}}/>
    

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 2015-06-17
      • 2018-06-11
      • 1970-01-01
      • 2017-04-22
      • 2011-05-30
      相关资源
      最近更新 更多