Migration Guide
Last updated
Last updated
This is a potentially breaking release:
fix multiple changeLanguage
call that may have result in wrong order in previous versions
adapt changeLanguage
to always (string or array) use getBestMatchFromCodes
getBestMatchFromCodes
now tries to fallback to language code with same script
remove support for older environments
remove old i18next
to convert your existing translations to the format, have a look at or this .
remove support for compatibility to the very first ()
is mandatory now and will not fallback anymore, use a polyfill ( and ) if your environment does not support it.
for those who really need the old behaviour, needs to create a compatibility layer similar to .
renamed initImmediate
to initAsync
fallback to dev
language if plural rule not found
Dropped support for Node.js < v14
Now only typescript >5
versions are supported. v4
types are now removed from the codebase.
jsonFormat
option has been removed. When a new json version will be released you can can use compatibilityJSON
option. which now only accepts v4
as value.
The redesign endeavors to enhance the approach to parsing and inferring keys for the t
function. Instead of performing a recursive examination of each key-value pair in resources
associated with specific namespace(s) each time the t
function is invoked, we generate a comprehensive set of keys from all namespaces just once.
Also use TypeScript v5.
These following codemods are available (see the notes in the "More information" section below):
setDebug
function in internal loggerreturnNull
option to false
rename option whitelist
to supportedLngs
rename option nonExplicitWhitelist
to nonExplicitSupportedLngs
rename function languageUtils.isWhitelisted
to languageUtils.isSupportedCode
If passing the ns
option, the defaultNS
will, by default, be set to the first ns passed.
When calling i18next.changeLanguage()
both i18next.language
and i18next.languages
will be set to the new language after calling loadResources
-> means when accessing t
function meanwhile you will get still the translations for the previous language instead of the fallback.
When is this breaking? this does not break any current test - but if you depend on accessing i18next.language or i18next.dir during language change and expect the new language this will break your app.
Reasoning: In react-i18next we get in a not ready state for loaded translations while we would prefer just waiting for the new language ready and trigger a rerender then - also a triggered rerender outside of the bound events would end in Suspense...
How can I get the language i18next will be set to? i18next.isLanguageChangingTo
is set to the language called
removes named exports in index.js to avoid issues in bundlers
Build process was updated - no API changes
note: dist/es -> dist/esm, dist/commonjs -> dist/cjs (individual files -> one bundled file)
Build process was updated - no API changes
typescript definitions now can directly be used from the i18next module - no longer needed to get them from DefinitelyTyped
functions used to return a callback (eg. init, changeLanguage, loadNamespaces) now also return a Promise - while this enables easier handling using async await this also means eg. i18next.init does not return this anylonger and therefore you can't chain calls like i18next.init().on()
anylonger.
pt-PT
Portugal Portuguese
plurals=2; plural=(n != 1);
pt_BR
Brazilian Portuguese
plurals=2; plural=(n > 1);
pt
Portuguese
plurals=2; plural=(n > 1);
With v9 we removed the compatibility for the v1 API. So the compatibilityAPI: 'v1'
flag won't do anything anymore.
The nonExplicitWhitelist
flag was changed to be used in user detected language too, before it was restricted to defined fallback languages only.
We used to resolve nb-NO, nn-NO to no as language part mainly because there was no way to proper define per local fallbacks. With v7.0.0 we removed that to enable default behaviour also for norwegian language. To get back the old behaviour you can define multiple fallbacks like:
Additional starting from 7.0.0 you could use named exports:
This change might break your e2e tests if your depending on the cimode (the returned value can now be set to return always only key or ns+key)
There is only a small change for webpack2 builds which now targets es build with import/export in place to enable treeshaking (module entrypoint in package.json).
Nothing breaking for non webpack2 users.
There is one breaking change regarding suffixing plurals in cases a language has multiple plural forms. Eg. arabic suffixes are now 0, 1, 2, 3, 4, 5 instead of 0, 1, 2, 3, 11, 100.
This change streamlines the suffix with the one used in gettext.
To enforce old behaviour you can enable compatibilityJSON = 'v2'
on i18next init call.
While v2.0.0 is a full rewrite of the old codebase it should be possible to run in your app without completely rewrite your integration.
The new version does not come with backend, cache and user language detection built in. i18next is more a core library that can be extended with modules on demand. This way it can be seamlessly used in browser, node.js or other javascript runtimes.
Modules are available on npm, via bower or on github to download.
Version 2.0.0 has a compatibility layer built in which allows to run it like v1.11.x. Keep in mind this layer will be removed in future version.
compatibilityAPI
Will convert init and t options and expose old API functions. Will be removed with future update.
compatibilityJSON
Will allow to use JSON files in v1 format. Using old interpolation prefix, suffix and no need for singular suffix [0] for singular in languages with more then just 1 plural form.
support for older browsers:
Beginning with v2 we target only modern browsers (Chrome, Firefox, ... and IE >= 10).
For IE9 you will need to add a es5 shim
jquery:
synchronous loading:
i18next.init({ getAsync: false });
is not supported any longer - as not encouraged by browsers.
no conflict:
i18n.noConflict();
was removed as i18next registers to window.i18next and no longer to window.i18n
indefinite article:
i18n.t('myKey', { indefinite_article: true })
was removed - as the solution was too limited - reconsidering adding a better solution in a future v2 release
redesigned the types to be less complex, faster and easier to maintain.\
Make sure your tsconfig compilerOptions has the flag or the set to true
.
To assist with the upgrade from i18n v22.x.x
to v23.0.0
, provides open-source codemods that automatically transform your code to many of the new APIs and patterns.
When loading multiple namespaces (), t
function will infer and accept the keys for the first namespace. So this pattern will be accepted now:
t
function will now infer interpolation values, but it'll only work if the translation files (resources) are placed in a ts file and using as const
(like ) or an (can be generated like ), JSON files don't support as const
to convert objects to be type literals (yet).
Based on we decided to remove the setDebug function.
To improve the usage for TypeScript users (in combination with React.js) we decided to set the returnNull
value to false
by default.
More information can be found .
To have smaller builds and faster loads, we now transpile only for modern browsers and runtimes. More information can be found .
To help translators, keys are now prefixed with _ordinal
.
Since this is a major rewrite for we decided to create a major version. For JavaScript users v22.0.0 is equivalent to 21.10.0
One of the biggest breaking changes is regarding suffixing plurals.
This change streamlines the suffix with the one used in the .
You may need to the API, in case it is not available it will fallback to the plural handling.
To enforce old behaviour you can enable compatibilityJSON = 'v3'
on i18next init call.
There is also support for (referring to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English). Learn more about plurals:
To convert your existing translations to the new v4 format, have a look at or . (It will only handle keys with the default pluralSeparator _
)
By default the skipOnVariables
now is set to true.
To enforce old behaviour you can set skipOnVariables = false
on i18next init call.
i18next now automatically tries to detect natural language keys.
This way there is no need to set nsSeparator
or keySeparator
to false
.
In case you want to skip this natural language detection, provide a keySeparator
and/or a nsSeparator
option.
The old and functions have been definitively removed.
There is a new property, that represents the current resolved language. It can be used as primary used language, for example in a language switcher.
There should not be any breaking change, but regarding of some misuse of i18next that pop up in last minor releases, we opted for a major version this time. The relevant change behind the scene for this major version was .
Typescript use export default
for esm-first approach . No API changes.
Breaking changes in typescript typings for details have a look at this .
plural form for hebrew was updated to latest . Before it had one plural form. You will have to update your JSON files containing hebrew plurals. Or patch back the plural form to: using the . Learn more about plurals:
removes plugin of type cache. Can be replace by example cache for localStorage
removes the support for multiload (multiRead) in backends - will just use read per language-namespace. You can enable multiRead support in backends again by using
brings pt, pt-PT, pt-BR plurals in line with, new pt reflects pt-BR and pt-PT gets a special case for plural handling
You still can append this manually as we do for our old v1 tests - .
Return namespace in cimode with appendNamespaceToCIMode option (default now will only return key without namespace - independent of call to t function)
Nested keys should not be escaped
i18next.cloneInstance() calls now init() (before it depended on having called that function with a callback)
hint for jquery user: use additional
use additional