Open ashitvora-zz opened 5 years ago
the xhr-backend loads file based on lng-ns --> so loading multiple namespaces in i18next will also load multiple files. See: https://www.i18next.com/how-to/add-or-load-translations#load-using-a-backend-plugin
Moment and Numeral provide locale config js files whereas i18next expects resource file in JSON format.
What I did in my init options is...
ns: ['common',
moment/${i18next.language},
numeral/${i18next.language}],
and here's what the loadPath function looks like...
loadPath: (lng: string, ns: string) => {
return `/locales/${lng}/${ns}.js`;
}
but obviously, this does not work. Is there a better option than this?
we did a lazy load of moment locales triggered by => https://www.i18next.com/overview/api#onlanguagechanged
onLanguageChanged
gets called after i18next.changeLanguage
is called and by that time the language has already been changed. Any event which can stop re-rendering till the moment, numeral locales are loaded.
how you trigger rerender?
languageChanging
event is called before...but still no guarantee that languageChanged
does not be called before your moment locales got loaded --> best make some custom function to changeLanguage loading those first and than call i18next.changeLanguage
I am able to load a single locale file by setting the path in loadPath but was wondering if there's a way to load multiple files by returning an array from loadPath function.
The use case is to load the translation file along with momentjs's locale file.