无法翻译< a> i18next库在div内标记 [英] Not able to translate <a> tag inside div by i18next library
问题描述
</head>
<body>
<div id="add">
<div data-i18n="key">You have to <a href="">Click here</a> to find better result</div>
//如果我使用的是翻译完整div并从文本中删除链接的方法.
// If I am using that way that translate complete div and remove link from my text.
<div data-i18n="key">You have to</div> <a href="" data-i18n="key2">Click here</a> <div data-i18n="key3">to find better result</div>
//如果我使用这种方式,代码可以正常工作,但是为此,我必须对单个句子使用3个键.是否可以通过单键修复?
// If I am using that way code working fine but for this I have to use 3 keys for single sentences. Is it possible to fix this by single key ?
<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>
此代码翻译了完整的div
This code translate complete div
推荐答案
a)将标签添加到翻译后的文本中. ->一键
a) Add the tag to your translated text. -> One key
"key": "You have to <a href="">Click here</a> to find better result"
和
<div data-i18n="html:key">You have to <a href="">Click here</a> to find better result</div>
设置innerHTML
to set innerHTML
b)将a标签插入翻译. ->两把钥匙
b) Interpolate the a tag into translation. -> Two keys
"key": "You have to {{link}} to find better result"
具有:
$('#add').localize({ link: '<a href="">Click here</a>', interpolation: { escapeValue: false }});
直接点击此处使用i18next.t进行翻译
translate Click here using i18next.t directly
这篇关于无法翻译< a> i18next库在div内标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!