You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

i18next插值报错:已传data-i18n-options仍提示缺少what变量如何解决

错误原因

你将jquery-i18next专属的两个配置项错误写入了i18next核心的初始化配置中:

  • optionsAttr
  • useOptionsAttr

这两个参数不属于i18next的原生配置,需要放到jqueryI18next.init的第三个参数里才能生效,否则jquery-i18next不会读取data-i18n-options属性的传值,插值时自然找不到what变量,触发报错。

修正方案

调整初始化代码的配置位置即可:

i18next.use(window.i18nextHttpBackend).init({
    debug: true,
    lng: new URL(window.location.href).searchParams.get('lang') || 'en',
    backend: {
      loadPath: './i18n/{{lng}}.json',
    },
  },
  function(err, t) {
    // 把两个配置移到jquery-i18next初始化参数中
    jqueryI18next.init(i18next, $, {
      optionsAttr: 'i18n-options',
      useOptionsAttr: true
    });
    $('[data-i18n]').localize();
  },
);

内容的提问来源于stack exchange,提问作者pavuk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 06:06:07