From 981f9a1028e8fbb9553b465bdd2a3b97645d1496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= <7397743+pelord@users.noreply.github.com> Date: Thu, 3 Oct 2019 16:26:16 -0400 Subject: [PATCH] fix(language) Get/set language is desynchronized(#453) * fix(language) Get/set language is desynchronized * --- .../core/src/lib/language/shared/language.service.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/src/lib/language/shared/language.service.ts b/packages/core/src/lib/language/shared/language.service.ts index 18f3d7da5d..b88f9df2f0 100644 --- a/packages/core/src/lib/language/shared/language.service.ts +++ b/packages/core/src/lib/language/shared/language.service.ts @@ -5,18 +5,20 @@ import { TranslateService } from '@ngx-translate/core'; providedIn: 'root' }) export class LanguageService { + private language: string = this.translate.getBrowserLang(); + constructor(public translate: TranslateService) { const lang = this.getLanguage(); this.translate.setDefaultLang(lang); } public getLanguage(): string { - const browserLang = this.translate.getBrowserLang(); - return browserLang.match(/en|fr/) ? browserLang : 'en'; + return this.language.match(/en|fr/) ? this.language : 'en'; } public setLanguage(language: string) { - this.translate.use(language); - this.translate.reloadLang(language); + this.language = language.match(/en|fr/) ? language : 'en'; + this.translate.use(this.language); + this.translate.reloadLang(this.language); } }