Created
April 4, 2019 22:15
-
-
Save theodesp/a4727324c30d0960c960b906096a6dba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule, Title } from '@angular/platform-browser'; | |
import { NgModule, APP_INITIALIZER, LOCALE_ID } from '@angular/core'; | |
import { I18NextModule, ITranslationService, I18NEXT_SERVICE, I18NextTitle, defaultInterpolationFormat } from 'angular-i18next'; | |
import { AppRoutingModule } from './app-routing.module'; | |
import { AppComponent } from './app.component'; | |
export function appInit(i18next: ITranslationService) { | |
return () => i18next.init({ | |
whitelist: ['en', 'gr'], | |
fallbackLng: 'en', | |
debug: true, | |
returnEmptyString: false, | |
ns: [ | |
'translation', | |
'validation', | |
'error', | |
], | |
interpolation: { | |
format: I18NextModule.interpolationFormat(defaultInterpolationFormat) | |
}, | |
}); | |
} | |
export function localeIdFactory(i18next: ITranslationService) { | |
return i18next.language; | |
} | |
export const I18N_PROVIDERS = [ | |
{ | |
provide: APP_INITIALIZER, | |
useFactory: appInit, | |
deps: [I18NEXT_SERVICE], | |
multi: true | |
}, | |
{ | |
provide: Title, | |
useClass: I18NextTitle | |
}, | |
{ | |
provide: LOCALE_ID, | |
deps: [I18NEXT_SERVICE], | |
useFactory: localeIdFactory | |
}]; | |
@NgModule({ | |
declarations: [ | |
AppComponent | |
], | |
imports: [ | |
BrowserModule, | |
AppRoutingModule, | |
I18NextModule.forRoot() | |
], | |
providers: [I18N_PROVIDERS], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment