Permalink
Switch branches/tags
Nothing to show
Find file Copy path
9cbac00 Apr 11, 2018
1 contributor

Users who have contributed to this file

51 lines (36 sloc) 1.04 KB

Context

Context

By providing a context you can differ translations. Eg. useful to provide gender specific translations.

Basic

keys

{
      "friend": "A friend",
      "friend_male": "A boyfriend",
      "friend_female": "A girlfriend"
}

sample

i18next.t('friend'); // -> "A friend"
i18next.t('friend', { context: 'male' }); // -> "A boyfriend"
i18next.t('friend', { context: 'female' }); // -> "A girlfriend"

Combining with plurals

You can pass entire data models in options.

keys

{
      "friend_male": "A boyfriend",
      "friend_female": "A girlfriend",
      "friend_male_plural": "{{count}} boyfriends",
      "friend_female_plural": "{{count}} girlfriends"
}

sample

i18next.t('friend', {context: 'male', count: 1}); // -> "A boyfriend"
i18next.t('friend', {context: 'female', count: 1}); // -> "A girlfriend"
i18next.t('friend', {context: 'male', count: 100}); // -> "100 boyfriends"
i18next.t('friend', {context: 'female', count: 100}); // -> "100 girlfriends"