Skip to content

Commit

Permalink
Language translation code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tysonpaul89 committed Mar 1, 2019
1 parent 8700c20 commit 840c6d1
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* This module is used to language translations.
* The translations are saved in a json file in /src/app/assets/i18n directory
* Docs: https://www.codeandweb.com/babeledit/tutorials/how-to-translate-your-angular7-app-with-ngx-translate
*/
import { NgModule } from '@angular/core';
import { HttpClient } from '@angular/common/http';

// import ngx-translate and the http loader
import {
TranslateLoader,
TranslateModule,
TranslateService
} from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

// ngx-translate - required for AOT compilation
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}

@NgModule({
declarations: [],
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
exports: [
TranslateModule
],
})
export class LanguageTranslationModule {
constructor(
private translate: TranslateService,
) {
// Gets Default language from browser if available, otherwise set English ad default
this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de', 'zh-CHS']);
this.translate.setDefaultLang('en');
const browserLang = this.translate.getBrowserLang();
this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de|zh-CHS/) ? browserLang : 'en');
}
}

0 comments on commit 840c6d1

Please sign in to comment.