... Angular adding multi language support ...
- VS Code
... We can add multi language functionality in angular by using @ngx-translate/core ...
npm install @ngx-translate/core
npm install @ngx-translate/http-loader
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
add in module/component .ts file
constructor(private translateSrv : TranslateService){
translateSrv.use('en');
}
in your app /src/assets create directory i8n and then create json file for languages which needs translation e.g en.json used for english, sv.json used for swedish etc..
{
"message": "Translated message from english"
}
{{'message' | translate}}
So in this case a 'Translated message from english' is showing as a translated message similary we can add multiple languages support by specify lanaguage in constructor along with JSON file in i8n directory.