![]() |
i18next Localization and Internationalization |
i18next (homepage) is a popular JavaScript internationalization library. It is used directly and through framework integrations such as react-i18next for React and i18next-vue for Vue. i18next stores the strings in JSON resource files. Soluling Desktop and Soluling Cloud support i18next resource files.
The end of the document contains links to get the full source code of the samples. After reading this document, we recommend reading a tutorial about how to use Soluling.
An i18next resource file is a JSON file whose values are strings. You can group the strings into nested objects. The following is a part of Sample.json of the sample.
{
"key": "value",
"keyDeep": {
"inner": "value"
},
"keyNesting": "reuse $t(keyDeep.inner)",
"keyInterpolate": "replace this {{value}}",
"keyContext_male": "the male variant",
"keyContext_female": "the female variant"
}
Soluling reads the file as follows:
| Item | Description |
|---|---|
| Strings | Each string value becomes a row. The path of the keys is the context of the row, for example, keyDeep.inner. |
| Interpolation | Placeholders such as {{value}}, {{- value}}, and {{value, format}} must be kept in the translation. |
| Nesting | References to other strings, such as $t(keyDeep.inner), must be kept in the translation. |
| Context | Context variants, such as keyContext_male and keyContext_female, are separate keys, so each of them is a separate row. |
| Arrays | The strings of an array, such as the items of arrayJoin in Array.json, are separate rows. |
When building, Soluling writes a localized resource file for each language. The localized file has the same keys and structure as the original file, but the values are translated.
i18next stores each plural form as a separate key with a suffix. Starting from i18next 21 (JSON format v4), the suffixes are the plural categories of the language, for example:
{
"item_one": "{{count}} item",
"item_other": "{{count}} items"
}
Older versions used _plural (JSON format v3, see Plural.json) or numbers such as _0 and _1 (JSON format v2, see Many.json).
Soluling reads the keys of a plural in the JSON v4 format as one plural string: item_one and item_other are the string item with the forms one and other. You translate the forms of the target language in the pattern editor, and the localized file gets the keys of those forms. For example, a Polish file gets item_one, item_few, item_many, and item_other, and a Japanese file gets only item_other, although the original file has item_one and item_other. When you import a localized file, Soluling imports its plural keys as the forms of the plural.
The ordinal keys, such as place_ordinal_one, and the _zero key, which i18next can use for a count of 0 in any language, are ordinary strings. So are the plural keys of the older formats: the localized file has the same keys as the original file.
A project made with an older Soluling version has a string for each plural key. When you scan it, the translations of those strings become the translation of the plural string, and the old strings become unused.
i18next applications usually load the resources of each language from a separate directory, for example, locales/en/translation.json and locales/fi/translation.json. By default, Soluling creates the localized files in language-specific subdirectories with the same name as the original file, for example, fi\Sample.json. If your original file is locales\en\translation.json, set the output directory on the Output sheet so that the localized files are written to locales\fi\translation.json and so on.
Sample.json) onto Soluling or click the New from File or Files button and select the file.fi\Sample.json.When you change the original resource file, open the Soluling project and choose Home | Scan. Soluling keeps the existing translations, and you only translate the strings that were added or changed.
With Soluling Cloud, you localize the resource file in your browser: upload the file, translate it in Translate, and download the localized files. You need a Soluling account. See the available Cloud plans.
locales/en/translation.json), or drag and drop the file onto the page. Click Create.Click the project's green Translate button on the dashboard. Translate opens the project, and you can type the translations into the grid. Machine translation suggestions, translation memory, and spell checking are available there. You do not have to finish every language before moving on to the next step.
locales/fi/translation.json.When you change the strings, upload the new original file, translate what is new or changed, and download the localized files again. On the dashboard, click the project's Update file button (the upload arrow), select the new file or drop it onto the page, and click Update. Existing translations are kept, so you only translate the strings that were added or changed.
The dashboard is one of four ways to use Soluling Cloud. You can also use the SoluCLI command-line tool, Soluling Desktop, or SoluMake, which can run the update and build steps in your build pipeline. See the Cloud tutorial for all of them.
GitHub and <data-dir>\Samples\i18next contain the following i18next sample files:
| File | Description | Notes |
|---|---|---|
| Sample.json | A resource file that contains plain and nested strings, nesting ($t()), interpolation, context, and plural keys. The localized Finnish file is in the fi subdirectory. |
Try this first! |
| Interpolation.json | A resource file that contains placeholders. | |
| Array.json | A resource file that contains arrays of strings and objects. | |
| Plural.json | Plural keys in the i18next JSON v3 format (_plural). |
No Soluling project |
| Many.json | Plural keys in the i18next JSON v2 format (_0 to _5). |
No Soluling project |
The React samples also contain an i18next application.
You create a resource file localization project by adding an i18next resource file (e.g., D:\Sample\locales\en\translation.json) into your Soluling project. You can configure how to localize your i18next resource file
by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.