Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
131 stars 33 forks source link

warnings on init (with fix !) #60

Closed mvidailhet closed 3 years ago

mvidailhet commented 3 years ago

Hi !

First of all, thanks for this repo ! I've been using i18next for my React projects and really wanted to use it for me Angular project as well !

I copied your code and found warnings after serving my Angular app :

i18next.js:22 i18next: hasLoadedNamespace: i18n.languages were undefined or empty undefined

and

i18next::translator: key "login-input_label_login" for languages "en" won't get resolved as namespace "translation" was not yet loaded This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!

I fixed it by adding lng: 'en' to the init of i18next and everything worked !

i18next.init({
  lng: 'en',
  whitelist: ['en', 'fr'],
  fallbackLng: 'en',
  debug: true,
  returnEmptyString: false,
  ns: ['translation', 'validation', 'error'],
  resources: {
    en: enTranslation,
    fr: frTranslation,
  },
});

Have a terrific day !

Romanchuk commented 3 years ago

Hello, make sure you done all installation steps (it loads namespaces before angular inits) https://github.com/Romanchuk/angular-i18next#installation