I try to implement i18next library for Angular in version 15. For implementation I use "angular-i18next": "^15.0.0-0" and "i18next": "^22.4.6" and below files:
.module.ts file:
import {NgModule} from '@angular/core';
import {I18NextModule} from 'angular-i18next';
import {I18N_PROVIDERS} from '@config/i18next.config';
const imports = [
I18NextModule.forRoot(),
]
@NgModule({
imports: [...imports],
providers: [
I18N_PROVIDERS,
],
})
export class CoreModule { }
and finaly config for i18next file:
import {APP_INITIALIZER, LOCALE_ID} from "@angular/core";
import {I18NEXT_SERVICE, ITranslationService} from 'angular-i18next';
import {registerLocaleData} from '@angular/common';
import i18nextLanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
import localePl from '@angular/common/locales/pl';
import {appSettings} from '@core/const/app-settings';
registerLocaleData(localePl, 'pl-PL')
export function appInit(i18next: ITranslationService) {
return () => i18next
.use(HttpApi)
.use(i18nextLanguageDetector)
.init({
supportedLngs: appSettings.languages,
fallbackLng: 'en-US',
debug: false,
returnEmptyString: false,
defaultNS: 'app',
load: 'currentOnly',
ns: [
'translation',
'validation',
'error',
],
})
}
export function localeIdFactory(i18next: ITranslationService) {
return i18next.language
}
export const I18N_PROVIDERS = [
{
provide: APP_INITIALIZER,
useFactory: appInit,
deps: [I18NEXT_SERVICE],
multi: true,
},
{
provide: LOCALE_ID,
deps: [I18NEXT_SERVICE],
useFactory: localeIdFactory,
},
]
On application start I receive following error:
Any ideas?
I tried modyfied several properties in i18next.init but same error still occours.