I18next - Provide a key in the data-i18n-options attribute for interpolation
I18next.js is currently in use and there is a problem.
Say two keys there:
{
'keyOne':'I am __name__',
'item': 'a person'
}
In html:
<div data-i18n="keyOne" data-i18n-options={"name":"item"}></div>
And the result that I would like:
"I am human"
If "person" is not a string literal but a key reference (for example using the data-i18n attribute)
Is it possible to provide the key "item" (not the string "person") for use in "keyOne" for interpolation? This would be helpful as when I change the language I only need to call .i18n () on the div and both keys will be translated. Without this feature, I would have to reevaluate the context and update the div manually.
Any help would be much appreciated. Thanks to
source to share
i18next has nesting functionality: http://i18next.com/translate/nesting/
So I could do what you want. You can check this jsfiddle: https://jsfiddle.net/leonardonsantos/3zy4xmnm/1/
Just change data-i18n-options
to $t
:
<div data-i18n="keyOne" data-i18n-options='{"name":"$t(item)"}'>
source to share