🐛 Bug Report
When call changeLanguage multiple times, if loadResources inside the changeLanguage resolved in different order, then the final language will be the last resolved changeLanguage call, instead of the last changeLanguage call.
To Reproduce
describe('changeLanguage', () => {
it('it should keep changeLanguage call in order', () => {
const instance = i18next.createInstance();
const makeLang = (lan, delay) => ({
delay,
value: {
foo: `${lan}`,
},
});
const langMap = {
en: makeLang('en', 100),
zh: makeLang('zh', 500),
es: makeLang('es', 300),
jp: makeLang('jp', 200),
};
return new Promise(resolve => {
instance
.use({
type: 'backend',
read: function(language, namespace, callback) {
const lang = langMap[language];
setTimeout(() => {
callback(null, lang.value);
}, lang.delay);
},
})
.init(
{
fallbackLng: 'en',
},
(err, t) => {
resolve(
Promise.all([
instance.changeLanguage('en'),
instance.changeLanguage('zh'),
instance.changeLanguage('jp'),
instance.changeLanguage('es'),
]).then(() => {
expect(t('foo')).to.equal('es');
}),
);
},
);
});
});
});
Expected behavior
Test not fail. The value of t('foo') is es
Your Environment
- runtime version: node v14.16.0
- i18next version: 20.2.1
- os: Linux
🐛 Bug Report
When call
changeLanguagemultiple times, ifloadResourcesinside thechangeLanguageresolved in different order, then the final language will be the last resolvedchangeLanguagecall, instead of the lastchangeLanguagecall.To Reproduce
Expected behavior
Test not fail. The value of
t('foo')isesYour Environment