[英]Interpolation i18next
I need help with interpolation in i18n.我需要 i18n 中的插值帮助。
I'm doing everything as written in the documentation, but I still get an error.我正在按照文档中的说明执行所有操作,但仍然出现错误。
i18next::interpolator: missed to pass in variable what for interpolating {{what}} some kind of sht.
i18next::interpolator: 错过了传入变量 what 来插入 {{what}} 某种类型的 sht。
My code:我的代码:
<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 (as same as any other language for testing): en.json(与用于测试的任何其他语言相同):
{
"key": "{{what}} some kind of sht."
}
jquery.i18n doc: enter link description here | jquery.i18n 文档: 在此处输入链接描述| i18next doc: enter link description here
i18next doc:在此处输入链接描述
What's wrong?怎么了?
I think you are mixing the jqueryI18next.init
options with i18next.init
options.我认为您将
jqueryI18next.init
选项与i18next.init
选项混合在一起。
optionsAttr
and useOptionsAttr
should probably be set in jqueryI18next.init
. optionsAttr
和useOptionsAttr
可能应该在jqueryI18next.init
设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.