Static i18n examples, using i18next and Locize vendor
i18n
refers to both static content and dynamic content, even though both are handled very differently.Read more about the concept
This section only showcases i18n for static content (nav, footer, etc.).
Dynamic content (DB records) is managed through Airtable and is completely unrelated.
NRN provides built-in static i18n support, based on:Dynamic content (DB records) is managed through Airtable and is completely unrelated.
-
i18next
package : Core dependency -
react-i18next
package : What we actually use in NRN, mostly throught thet
andTrans
component. - Locize vendor packages (paid) : Vendor meant to help with static content localisation. Read our "How to use" and learn more about what benefits it brings
Each example below shows the rendered version and the associated code snippet.
The goal is to showcase real-world examples to help you get started faster and give a wider overview of what's possible.
Check the official documentation
The goal is to showcase real-world examples to help you get started faster and give a wider overview of what's possible.
Check the official documentation
Translation using t
function
Traduction simple
1
2
3
{t('examples.i18n.simpleTranslation', 'Traduction simple')}
Translation with plurals
Plurals work with the
It's a very particular variable, only meant for that purpose.
Read the doc
count
property, which is the amount of items.It's a very particular variable, only meant for that purpose.
Read the doc
Traduction avec gestion du pluriel
1
2
3
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 1 })}
Traduction avec gestion des pluriels
1
2
3
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 2 })}
Nous avons trouvé 1 solution pour vous.
1
2
3
4
5
6
7
8
<Trans
i18nKey={'examples.i18n.dynamicPluralTranslation'}
count={1}
>
Nous avons trouvé {{ count: 1 }} solution pour vous.
</Trans>
Nous avons trouvé 2 solutions pour vous.
1
2
3
4
5
6
7
8
<Trans
i18nKey={'examples.i18n.dynamicPluralTranslation'}
count={2}
>
Nous avons trouvé {{ count: 2 }} solution pour vous.
</Trans>
Translation using variables
Automated fallback - Handling missing translations
It will happen that some translations are missing, in such case NRN has been configured to fallback to another language (AKA "fallback" language).
French has been defined as the default language in NRN (Locize configuration), meaning all translations must always exist for the French language.
French has been defined as the default language in NRN (Locize configuration), meaning all translations must always exist for the French language.
Cette phrase n'est pas traduite en anglais, et sera affichée en Français même quand la langue anglaise est utilisée
(This sentence is not translated in English, and will be displayed in French even when English language is being used)
Note that I actually translated it (within the same sentence), so that non-French speakers may understand the explanation/feature.
Basically, if a static translation is not found in any non-primary language, then NRN automatically fall backs to another language, so that something gets displayed in any way.
(This sentence is not translated in English, and will be displayed in French even when English language is being used)
Note that I actually translated it (within the same sentence), so that non-French speakers may understand the explanation/feature.
Basically, if a static translation is not found in any non-primary language, then NRN automatically fall backs to another language, so that something gets displayed in any way.
1
2
3
4
5
6
7
8
9
10
11
12
<Trans
i18nKey={'examples.i18n.missingTranslationWithFallback'}
>
Cette phrase n'est pas traduite en anglais, et sera affichée en Français même quand la langue anglaise est utilisée<br />
(This sentence is not translated in English, and will be displayed in French even when English language is being used)<br />
<i>
Note that I actually translated it (within the same sentence), so that non-French speakers may understand the explanation/feature.<br />
Basically, if a static translation is not found in any non-primary language, then NRN automatically fall backs to another language, so that something gets displayed in any way.
</i>
</Trans>
Customising translations, per customer
You may need to allow some translations to be overridden by a particular customer.
NRN comes with built-in support for this advanced need, and uses additional Locize "Languages" to store "variations" of the translations.
NRN comes with built-in support for this advanced need, and uses additional Locize "Languages" to store "variations" of the translations.
Cette traduction est spécifique au customer "customer1".
Chaque customer peut surcharger ses propres traductions, en créant une clé Locize dans son
Cette traduction va surcharger/remplacer la traduction de base, pour ce customer.
Exemple: Je suis Customer 1 et je peux écrire ce que je veux ici, ça ne s'affichera pas chez les autres clients.
Chaque customer peut surcharger ses propres traductions, en créant une clé Locize dans son
"fr-x-customer1"
langage.Cette traduction va surcharger/remplacer la traduction de base, pour ce customer.
Exemple: Je suis Customer 1 et je peux écrire ce que je veux ici, ça ne s'affichera pas chez les autres clients.
1
2
3
4
5
6
7
8
9
10
11
<Trans
i18nKey={'examples.i18n.translationUsingCustomerVariation'}
>
Cette traduction est spécifique au customer "{{ customerRef: process.env.NEXT_PUBLIC_CUSTOMER_REF }}". <br />
Chaque customer peut surcharger ses propres traductions, en créant une clé Locize dans son <code>"{{ customerVariationLang: resolveCustomerVariationLang(lang)}}"</code> langage.<br />
Cette traduction va surcharger/remplacer la traduction de base, pour ce customer.<br />
<br />
Exemple:
</Trans>
This requires you create a new
The
Language
in Locize first, for instance: fr-x-customer1
and en-x-customer1
The
-x-
stands for "variation", it's the official way to create custom language variations that are specific to your business needs, when using i18next.You will need to check how this page displays on other customers to see this particular behaviour.
Check out the README to see all other demos. (e.g: customer 1/2)
Check out the README to see all other demos. (e.g: customer 1/2)