i18next v26.5.0

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' and parseInterpolation: 'mf2' type t() options from the message's ICU MessageFormat arguments (i18next-icu) or MessageFormat 2 variables (i18next-mf2), so ICU and MF2 users no longer need parseInterpolation: false and 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, default true is unchanged.
    • ICU: {name} takes string | number, {n, number}, plural and selectordinal take number, {d, date} and {t, time} take Date, select takes its case keys or any string (for other), and arguments nested in cases are required too. # and tags are not arguments, apostrophe quoting is read like intl-messageformat does.
    • MF2: {$name} takes string | number, a variable annotated with :number, :integer, :currency, :percent or :unit (inline or through .input / .local) takes number, :datetime, :date and :time take Date, :string takes string, option and markup variables (minimumFractionDigits=$digits, {#link href=$url}) are required too, .local variables are not arguments, and |quoted literals| and \{ escapes are skipped.
    • interpolationFormatTypeMap overrides a type by ICU format or MF2 function name, e.g. date: Date | number or a custom uppercase: string.
    • Applies to t(), getFixedT(), i18n.t, key prefixes, namespaces, the selector API and react-i18next's Trans values. Messages need literal types, as the resources file from i18next-cli's types command 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.
  • 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.
View original

Upgraded? How did it go?

Discussion