Romanchuk / angular-i18next

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

Initialization Error and Language Switching Failure with Latest Version of Angular-i18next in Angular 18.1.0 #125

Closed abdosalehpkcs closed 1 month ago

abdosalehpkcs commented 1 month ago

Hello

I've encountered an issue while setting up the latest version of angular-i18next in my Angular 18.1.0 application that is built with module-federation. The problem arises during the initialization phase with the following error:

TypeError: Cannot read properties of undefined (reading 'call') at I18NextService.subscribeEvents (angular-i18next.mjs:391:25) at I18NextService.init (angular-i18next.mjs:323:14) at app.modules.ts:13:10

Upon investigating how the i18next service is provided, I noticed it is wrapped in an InjectionToken. I attempted to initialize it using the following approach:

   const promise: Promise<I18NextLoadResult> = (i18next as any).i18next
        .use(HttpApi)
        .init({
            supportedLngs: ['en', 'de'],
            fallbackLng: 'en',
            debug: true,
            returnEmptyString: false,
            ns: [
              'translation',
            ],
            backend: {
                loadPath: '/assets/i18n/{{lng}}.{{ns}}.json',

            }
          });
   return promise;

How can I resolve this issue to ensure the language switching works correctly with the latest version of angular-i18next?

Reproducing Issue: sandbox Preview: https://dyx2jl-35923.csb.app/

abdosalehpkcs commented 1 month ago

I will be closing this issue as It worked for me after a shared the library through an npm lib where i created wrappers for what i needed to use in all mfes