Created
July 27, 2020 14:56
Translation and globalization in Ionic 5 - Translation with ngx-translate
This file contains 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 { NgModule } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { RouteReuseStrategy } from '@angular/router'; | |
import { IonicModule, IonicRouteStrategy } from '@ionic/angular'; | |
import { SplashScreen } from '@ionic-native/splash-screen/ngx'; | |
import { StatusBar } from '@ionic-native/status-bar/ngx'; | |
import { AppRoutingModule } from './app-routing.module'; | |
import { AppComponent } from './app.component'; | |
import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; | |
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; | |
import { HttpClientModule, HttpClient } from '@angular/common/http'; | |
import { Globalization } from '@ionic-native/globalization/ngx'; | |
export function HttpLoaderFactory(http: HttpClient) { | |
return new TranslateHttpLoader(http, "./assets/i18n/", ".json"); | |
} | |
@NgModule({ | |
declarations: [AppComponent], | |
entryComponents: [], | |
imports: [ | |
HttpClientModule, | |
BrowserModule, | |
TranslateModule.forRoot({ | |
loader: { | |
provide: TranslateLoader, | |
useFactory: HttpLoaderFactory, | |
deps: [HttpClient] | |
} | |
}), | |
IonicModule.forRoot(), AppRoutingModule], | |
providers: [ | |
StatusBar, | |
SplashScreen, | |
Globalization, | |
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy } | |
], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment