i18next: Can not get current language
When I query i18next
for current language it always comes back undefined. Retrieving keys and changing languages works fine.
import i18next from 'i18next';
import { reactI18nextModule } from 'react-i18next';
import en_US from './en_US.json';
import fr_CA from './fr_CA.json';
import es_US from './es_US.json';
import en_CA from './en_CA.json';
i18next.use(reactI18nextModule).init({
resources: {
en_US: { translations: en_US },
fr_CA: { translations: fr_CA },
es_US: { translations: es_US },
en_CA: { translations: en_CA },
},
lng: 'en_US',
fallbackLng: 'en_US',
ns: ['translations'],
defaultNS: 'translations',
debug: true,
react: {
wait: true,
defaultTransParent: 'span',
},
});
export default i18next;
import React from 'react';
import i18next, { t, changeLanguage, language } from 'i18next';
export const getLocale = () => {
return language; //this will always be undefined,
};
Console logging out i18next
shows this
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (8 by maintainers)
For anyone else following, I was able to keep my locales using
_
@HuyAms please open a new issue with detailed information so we can reproduce…i can’t remote guess your code 😁
I fixed it, it seems like accessing the
language
like thisimport i18next, { t, changeLanguage, language } from 'i18next';
totally breaks it. As soon as i removed any reference to that it started to working. Thanks for the debugging help.