【问题标题】:i18next not loading files in backendi18next 不在后端加载文件
【发布时间】:2018-04-20 04:49:53
【问题描述】:

您好,我在我的 Node JS 应用程序中使用 i18next。 以下是 i18next 的配置代码:

const i18nextBackend = require('i18next-node-fs-backend');

 i18n
  .use(i18nextBackend)
  .init({
    fallbackLng: 'en',
    debug: true,
    backend: {
      loadPath: 'locales/{{lng}}.json',
      addPath: 'locales/{{lng}}.json',
      jsonIndent: 2,
    },
  }, (err, t) => {
    // init set content
    console.log(t);
    // console.log('INIT DONE');
  });
  console.log(i18n.t('hello'));

我的语言环境文件夹中有 en.js,其中有 JSON 格式的数据。但是文件无法加载。谁能告诉如何正确地在 loadPath 中给出路径名?

【问题讨论】:

    标签: javascript node.js internationalization i18next


    【解决方案1】:

    看起来您根本没有添加后端插件。 https://github.com/i18next/i18next-node-fs-backend 文件系统后端可能是您搜索的内容

    【讨论】:

    • 我通过添加后端插件进行了编辑。但是错误仍然存​​在,错误是:Uncaught TypeError: _fs2.default.readFile is not a function
    • 你能给我一个小例子,我可以理解从文件中获取数据的工作原理。
    猜你喜欢
    • 2021-11-03
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 2019-03-03
    • 2021-09-24
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多