ICU and MF2 messages
Extract, lint and type messages written in MessageFormat (ICU) or MessageFormat 2.
If your translations are written in ICU MessageFormat (i18next-icu) or Unicode MessageFormat 2 (i18next-mf2), tell the CLI:
typescript
export default defineConfig({
locales: ['en', 'de', 'ru'],
extract: {
input: ['src/**/*.{ts,tsx}'],
output: 'locales/{{language}}/{{namespace}}.json',
messageFormat: 'icu', // or 'mf2'
},
})
What it changes:
extractwrites one key per message.t('photos', '{count, plural, one {# photo} other {# photos}}', { count })givesphotos, notphotos_oneandphotos_other, andcontextadds no_malekeys, because ICU and MF2 keep plurals and selects inside the message and the plugins never read suffix keys.$t()in a value is text, not nesting. Plural suffix keys left over from an earlier extraction are removed like other unused keys.extractwrites the children of<Trans>with{name}(ICU) or{$name}(MF2) in the value; the key of a<Trans>withouti18nKeystays what react-i18next builds at runtime (Hello {{name}}).extractreadsIcuTransandIcuTransWithoutContext(also when imported under another name): the key isi18nKey, ordefaultTranslationwhen there is none, anddefaultTranslationis the value. The components ofreact-i18next/icu.macro(Trans,Plural,Select,SelectOrdinal) are extracted with the message the macro builds, for example<Trans i18nKey="welcome">Welcome, <strong>{name}</strong>!</Trans>givesWelcome, <0>{name}</0>!. These two are recognized in every format, without adding them totransComponents.statuscounts a plural or select message as one key.instrumentwrites{name}/{$name}placeholders and escapes the text around them (File '{{name}}'becomesFile ''{name}', since an apostrophe before{starts quoted text in ICU), a ternary likecount === 1 ? 'task' : 'tasks'becomes one plural message ({count, plural, one {…} other {…}}, MF2.match $count) instead ofdefaultValue_one/defaultValue_other, and the i18n init file it creates registersi18next-icuori18next-mf2.lintparses every translation value and reports syntax errors, arguments that differ from the primary language and plural categories that do not fit a locale (seelint). Thet()interpolation check reads the arguments with the same parser.typessetsparseInterpolation: 'icu'or'mf2'in a newly generatedi18next.d.ts, sot()options are type-checked against each message's arguments (i18next 26.5.0 or later; with older versions it setsparseInterpolation: false).
What keeps and what stops working at runtime with these formats (plural and context suffix keys, $t() nesting, i18next formatters, escapeValue) is described in Using ICU or MF2.