【问题标题】:React i18next modify translation file pathReact i18next 修改翻译文件路径
【发布时间】:2023-02-20 19:16:51
【问题描述】:

我正在使用带有 react-i18next 的 React 应用程序,我正在从路径加载翻译

locales/en/translation.json
locales/de/translation.json
locales/fr/translation.json
...

我可以更改路径并从中加载翻译吗

lib/en.i18n.json
lib/de.i18n.json
lib/fr.i18n.json
...

非常感谢

【问题讨论】:

    标签: javascript reactjs translation i18next


    【解决方案1】:

    更新 i18n 库的配置。

    import i18n from 'i18next';
    import XHR from 'i18next-xhr-backend';
    
    i18n
      .use(XHR)
      .init({
        backend: {
          loadPath: 'lib/{{lng}}.i18n.json',
        },
        // ... other i18n options ...
      });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-07
      • 2017-02-11
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 2022-06-12
      • 2013-07-21
      相关资源
      最近更新 更多