错过传递变量 yes 用于在 i18next 中进行插值

missed to pass in variable yes for interpolating in i18next

</head>

<body>
    <div id="add">
        <div data-i18n="key">Hello</div>
    </div>
    <script>
        i18next.t('key', {yes: 'this', no: 'great'});
    </script>
    <script>
        i18next
        i18next.use(window.i18nextBrowserLanguageDetector)
        i18next.use(window.i18nextXHRBackend)

        .init({
            debug: true,
            tName: 't',
            handleName: 'localize',
            selectorAttr: 'data-i18n',
            targetAttr: 'i18n-target',
            optionsAttr: 'i18n-options',
            useOptionsAttr: true,
            parseDefaultValueFromContent: true,
            initImmediate: true,
            fallbackLng: false,
            interpolation: {
                "escapeValue": true,
                "prefix": "{{",
                "suffix": "}}",
                "formatSeparator": ",",
                "unescapePrefix": "-",
                "nestingPrefix": "$t(",
                "nestingSuffix": ")"
            },

            detection: {
                order: ['querystring', 'cookie', 'navigator', 'htmlTag'],
                lookupCookie: 'i18next',
                lookupLocalStorage: 'i18nextLng',
                caches: ['cookie'],
            },

            "backend": {
                "loadPath": "/locales/{{lng}}/{{ns}}.json"
            }

        }, function(err, t) {
            jqueryI18next.init(i18next, $);
            $('#add').localize();
        });

    </script>

</body>

Json 文件

{ "key":“{{是}}是{​​{否}}”

}

控制台结果

i18next::interpolator: 错过传递变量 yes 用于插值 {{yes}} 是 {{no}}

i18next::interpolator: 错过了为插值传入的变量 no 是 {{no}}

这段代码有什么问题吗?

谢谢

您在初始化完成之前调用 i18next.t('key', {yes: 'this', no: 'great'});

你应该:

``` 。在里面({ ...

    }, function(err, t) {
        jqueryI18next.init(i18next, $);
        // add vars here!!!
        $('#add').localize({yes: 'this', no: 'great'});
    });

```

或者使用data-i18n-option属性:https://github.com/i18next/jquery-i18next#using-options-in-translation-function