【问题标题】:Interpolation i18next插值 i18next
【发布时间】:2021-12-20 08:22:31
【问题描述】:

我需要 i18n 插值方面的帮助。

我正在按照文档中的说明执行所有操作,但仍然出现错误。

i18next::interpolator: 错过了传入变量 what 用于插值 {{what}} 某种 sht。

我的代码:

<body>
  <span data-i18n="key" data-i18n-options='{ "what": "i18n"}'></span>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/8.1.0/i18next.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.0/jquery-i18next.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.1/i18nextHttpBackend.min.js"></script>
  <script>
    i18next.use(window.i18nextHttpBackend).init({
        debug: true,
        // url.com?lang=en | url.com?lang=ru
        lng: new URL(window.location.href).searchParams.get('lang') || 'en',
        optionsAttr: 'i18n-options',
        useOptionsAttr: true,
        backend: {
          loadPath: './i18n/{{lng}}.json',
        },
      },
      function(err, t) {
        jqueryI18next.init(i18next, $);
        $('[data-i18n]').localize();
      },
    );
  </script>
</body>

en.json(与任何其他测试语言相同):

{
    "key": "{{what}} some kind of sht."
}

jquery.i18n 文档:enter link description here | i18next 文档:enter link description here

怎么了?

【问题讨论】:

    标签: javascript jquery string-interpolation i18next


    【解决方案1】:

    我认为您将jqueryI18next.init 选项与i18next.init 选项混合在一起。

    optionsAttruseOptionsAttr 应该设置在jqueryI18next.init 中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2022-04-16
    • 2015-08-12
    • 2013-08-18
    • 2017-04-22
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多