Formats
i18next JSON
Translate i18next JSON translation files (v4), including plural-suffix keys and interpolation.
i18next stores its translations as JSON files, one folder per locale, in the i18next JSON v4 format (the default since i18next v21).
Install the format package:
npm install -D @eloqnt/format-i18next-json
Then reference it from your configuration:
.eloqnt/config.ts
import {defineConfig} from '@eloqnt/cli';export default defineConfig({messages: {path: './locales/{locale}/{namespace}',locales: 'infer',sourceLocale: 'en',format: {codec: '@eloqnt/format-i18next-json',extension: '.json'}}});
This matches files like:
locales/en/common.jsonlocales/en/settings.json- etc.
Plurals
i18next spells plurals as key suffixes, one key per plural form:
locales/en/translation.json
{"cart_one": "{{count}} item","cart_other": "{{count}} items"}
eloqnt/cli parses this as ICU for operations like eloqnt lint and eloqnt translate:
{count, plural, one {{count} item} other {{count} items}}
This is only an intermediate representation that serializes back to i18next JSON.
Note: The _other form is required for a group of keys to be recognized as a plural.
Not supported
The following features are not supported:
- i18next JSON v3 and older: Please migrate to v4.
- Array values: Their items are positional and unnamed, which is why most localization tools can't translate them reliably. Give each item its own key instead.
srcPath: Source code analysis is currently limited tonext-intl.