![](/img/trans.png)
[英]React components in i18next interpolation display as [object Object]
[英]Interpolation i18next
我需要 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 文檔: 在此處輸入鏈接描述| i18next doc:在此處輸入鏈接描述
怎么了?
我認為您將jqueryI18next.init
選項與i18next.init
選項混合在一起。
optionsAttr
和useOptionsAttr
可能應該在jqueryI18next.init
設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.