importi18nextfrom'i18next'consti18n=i18next({lng: 'en'})i18n.addHook('extendOptions',async()=>{constadditionalOptions=awaittakeOptionsFromSomewhere()returnadditionalOptions})// ori18n.addHook('extendOptions',()=>{constsomeComputedValue=2+Math.random()return{special: someComputedValue}})i18n.addHook('loadResources',()=>({en: {translation: {'my.key': 'a value'}}}))i18n.addHook('resolvePlural',(count,key,lng,options)=>`${key}_${count}`)i18n.addHook('resolveKey',(key,ns,lng,res,options)=>res[lng][ns][key])i18n.on('initialized',(i18n)=>{console.log('i18next has been initialized')})awaiti18n.init()i18n.t('my.key')// a value
Some differences:
not a singleton anymore
handles nested and flat resources automatically
automatic detection when using natural language keys
automatic detection when returning objects
more customizable
interpolation: automatic escaping of regex prefixes/suffixes
interpolation: no nesting anymore
Intl plural rules (cardinal and ordinal)
offer resolvedLanguage to be used i.e. in a language switcher
separate compatibility layer for plugins
separate compatibility layer for old i18next behaviour (plurals and nesting)