Objects and Arrays

Objects

You can return objects or arrays to be used by third party modules localization:
keys
1
{
2
"tree": {
3
"res": "added {{something}}"
4
},
5
"array": ['a', 'b', 'c']
6
}
Copied!
sample
1
i18next.t('tree', { returnObjects: true, something: 'gold' });
2
// -> { res: 'added gold' }
3
4
i18next.t('array', { returnObjects: true });
5
// -> ['a', 'b', 'c']
Copied!
The returned value supports interpolation, plurals, nesting, ...
returnObjects can be set to true on init.

Arrays

You can access array values or join them.
keys
1
{
2
"arrayJoin": [
3
"line1",
4
"line2",
5
"line3"
6
],
7
"arrayJoinWithInterpolation": [
8
"you",
9
"can",
10
"{{myVar}}"
11
],
12
"arrayOfObjects": [
13
{ "name": "tom" },
14
{ "name": "steve" }
15
]
16
}
Copied!
sample
1
i18next.t('arrayJoin', { joinArrays: '+' });
2
// -> "line1+line2+line3"
3
4
i18next.t('arrayJoinWithInterpolation', { myVar: 'interpolate', joinArrays: ' ' });
5
// -> "you can interpolate"
6
7
i18next.t('arrayOfObjects.0.name');
8
// -> "tom"
Copied!
The returned value supports interpolation, plurals, nesting, ...
joinArrays can be set to a value on init.
Last modified 1mo ago
Copy link