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

Basic

keys
1
{
2
"friend": "A friend",
3
"friend_male": "A boyfriend",
4
"friend_female": "A girlfriend"
5
}
Copied!
sample
1
i18next.t('friend'); // -> "A friend"
2
i18next.t('friend', { context: 'male' }); // -> "A boyfriend"
3
i18next.t('friend', { context: 'female' }); // -> "A girlfriend"
Copied!

Combining with plurals

You can pass entire data models in options.
keys
1
{
2
"friend_male_one": "A boyfriend",
3
"friend_female_one": "A girlfriend",
4
"friend_male_other": "{{count}} boyfriends",
5
"friend_female_other": "{{count}} girlfriends"
6
}
Copied!
sample
1
i18next.t('friend', {context: 'male', count: 1}); // -> "A boyfriend"
2
i18next.t('friend', {context: 'female', count: 1}); // -> "A girlfriend"
3
i18next.t('friend', {context: 'male', count: 100}); // -> "100 boyfriends"
4
i18next.t('friend', {context: 'female', count: 100}); // -> "100 girlfriends"
Copied!
Last modified 1mo ago