Created
June 5, 2017 14:32
-
-
Save anteburazer/02048642eae658865ea1a9f1948dc13b to your computer and use it in GitHub Desktop.
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
private setupLanguage(): void { | |
// Load localization object from the confguration | |
let localization: any = this.configService.get('localization'); | |
// Save language codes as an array | |
let languages: Array<string> = localization.languages.map(lang => lang.code); | |
// Get browser’s default language | |
let browserLang: string = this.translate.getBrowserLang(); | |
// Tell the translate service for the available languages and set a | |
// default one | |
this.translate.addLangs(languages); | |
this.translate.setDefaultLang(localization.defaultLanguage); | |
// The default language will be a default language from the configuration | |
// or selected browser language if it matches one of our predefined values | |
let browserMatch = browserLang.match(/en|hr/); | |
let selectedLang = browserMatch ? browserLang : localization.defaultLanguage; | |
let selectedCulture = localization.languages.filter(lang => { | |
return lang.code === selectedLang; | |
})[0].culture; | |
// Tell the translate service to use selected language | |
this.translate.use(selectedLang); | |
// Save selected language and culture in the store | |
this.appState$.dispatch(new settingsActions.SetLanguageAction(selectedLang)); | |
this.appState$.dispatch(new settingsActions.SetCultureAction(selectedCulture)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment