Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (54 sloc) 1.24 KB

Objects and Arrays

Objects and arrays

Objects

You can return objects or arrays to be used by third party modules localization:

keys

{
    "tree": {
        "res": "added {{something}}"
    },
    "array": ['a', 'b', 'c']
}

sample

i18next.t('tree', { returnObjects: true, something: 'gold' });
// -> { res: 'added gold' }

i18next.t('array', { returnObjects: true });
// -> ['a', 'b', 'c']

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

{
      "arrayJoin": [
        "line1",
        "line2",
        "line3"
      ],
      "arrayJoinWithInterpolation": [
        "you",
        "can",
        "{{myVar}}"
      ],
      "arrayOfObjects": [
        { "name": "tom" },
        { "name": "steve" }
      ]
}

sample

i18next.t('arrayJoin', { joinArrays: '+' });
// -> "line1+line2+line3"

i18next.t('arrayJoinWithInterpolation', { myVar: 'interpolate', joinArrays: ' ' });
// -> "you can interpolate"

i18next.t('arrayOfObjects.0.name');
// -> "tom"

The returned value supports interpolation, plurals, nesting, ...

joinArrays can be set to a value on init.

You can’t perform that action at this time.