Skip to content

Commit

Permalink
fix(language) Get/set language is desynchronized(#453)
Browse files Browse the repository at this point in the history
* fix(language)  Get/set language is  desynchronized

*
  • Loading branch information
pelord authored and mbarbeau committed Oct 3, 2019
1 parent 58b89c2 commit 981f9a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/lib/language/shared/language.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 981f9a1

Please sign in to comment.