[WP] 28.03.2023 | i18-next

fig 1.1 i18next ecosystem scheme

--------------------------------------------------------

  i18next is a library used for internationalization of webapp. There is a variety of library variants for major frontend frameworks.

It may be included into a project by installing appropriate package(eg. npm i react-i18next) and creating langs folder. Within the langs folder we should include separate language definitions (eg. pl.ts). i18next object need to be initialized in index.ts file(src/common/i18next/index.ts)Within i18next config we can pass settings such as fallback language(language to be used in case of missing translation).


Language definitions are recorded in form of nested objects with translation dictionary (key-value pairs) . They are exported to the components which require to be translated. Translation is done by use translation function. After importing the instance of use translation funciton is passed to t variable. Whenever translated text is required new record is to be created on translations object(/src/common/i18next/langs/pl.ts) after that translation is injected with t(`group.key`) group symbolizes name of one of the multiple nested top-level objects with key-value translation pairs. Key is alias for given word and value is a word describing given object in particular language. Above mentioned use of i18next library uses local dictionary files. Another possibility assumes connecting to translate api in order to obtain translations(backend).


regards

gmarcin

Komentarze

Popularne posty z tego bloga

[WP] 23.06.2023 | subjects

15.07.2024 | simplicity

[WP] 05.06.2023 | angular-intro