v26.5.0
Added 4
- Opt-in parseInterpolation: 'icu' and parseInterpolation: 'mf2' options type t() interpolation arguments from ICU MessageFormat arguments (i18next-icu) or MessageFormat 2 variables (i18next-mf2), so ICU and MF2 users no longer need parseInterpolation: false and keep argument checking.
- ICU type checking reports missing, misspelled and wrongly typed arguments, including arguments nested in plural, select and selectordinal cases, and reports an error naming the missing arguments when options are omitted for a message with arguments.
- MF2 type checking reports missing, misspelled and wrongly typed variables, including option and markup variables, while skipping .local variables, quoted literals and backslash escapes.
- interpolationFormatTypeMap overrides the argument type for a given ICU format or MF2 function name, such as date: Date | number or a custom uppercase: string.
Changed 1
- Interpolation argument type checking applies to t(), getFixedT(), i18n.t, key prefixes, namespaces, the selector API and react-i18next's Trans values, and requires messages to have literal types as produced by the i18next-cli types command.
Fixed 1
- With the default non-strict key checks, an options object with a missing or misspelled interpolation variable now reports the missing variable (Property 'name' is missing) instead of a not-assignable error from the default-value overload.
From i18next
- feat(types):
parseInterpolation: 'icu'andparseInterpolation: 'mf2'typet()options from the message's ICU MessageFormat arguments (i18next-icu) or MessageFormat 2 variables (i18next-mf2), so ICU and MF2 users no longer needparseInterpolation: falseand lose argument checking. Missing, misspelled and wrongly typed arguments fail, and so does leaving out the options for a message with arguments (t('greeting')); that error names the missing arguments. Opt-in, defaulttrueis unchanged.- ICU:
{name}takesstring | number,{n, number},pluralandselectordinaltakenumber,{d, date}and{t, time}takeDate,selecttakes its case keys or any string (forother), and arguments nested in cases are required too.#and tags are not arguments, apostrophe quoting is read like intl-messageformat does. - MF2:
{$name}takesstring | number, a variable annotated with:number,:integer,:currency,:percentor:unit(inline or through.input/.local) takesnumber,:datetime,:dateand:timetakeDate,:stringtakesstring, option and markup variables (minimumFractionDigits=$digits,{#link href=$url}) are required too,.localvariables are not arguments, and|quoted literals|and\{escapes are skipped. interpolationFormatTypeMapoverrides a type by ICU format or MF2 function name, e.g.date: Date | numberor a customuppercase: string.- Applies to
t(),getFixedT(),i18n.t, key prefixes, namespaces, the selector API and react-i18next'sTransvalues. Messages need literal types, as the resources file from i18next-cli'stypescommand has them. - Type-check cost with 1,000 messages and one call each: 1.35s instead of 0.86s with
false(TypeScript 6), 0.5s instead of 0.26s with TypeScript 7. Messages that no call uses cost nothing.
- ICU:
- fix(types): with the default (non-strict) key checks, an options object with a missing or misspelled interpolation variable now reports the missing variable (
Property 'name' is missing) instead of'{ nmae: string }' is not assignable to type 'string'from the default-value overload.