From 30437d24feaab721a66e889c3af26ca5f9274d5e Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Wed, 20 Feb 2019 15:57:30 +0100 Subject: [PATCH] fix language intialization for non-supported languages --- src/app/app.component.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7a7e15c..ca23549 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -26,7 +26,7 @@ export class openSenseApp { title: 'MENU.DOCS', icon: 'book', callback: () => { - window.open('https://sensebox.github.io/books-v2/blockly/' + this.translate.currentLang) + window.open(`https://sensebox.github.io/books-v2/blockly/${this.translate.currentLang}/`) } }, { @@ -48,7 +48,8 @@ export class openSenseApp { splashScreen: SplashScreen, ) { this.translate.setDefaultLang(DEFAULT_LANG) - this.translate.use(this.translate.getBrowserLang()) // @TODO: check if this works on all platforms! + this.translate.use(this.getPreferredLanguage()) + platform.ready() .then(() => { if ((window).cordova) { @@ -66,8 +67,15 @@ export class openSenseApp { // Reset the content nav to have just this page // we wouldn't want the back button to show in this scenario + // this.nav.setRoot(page.component); this.nav.setRoot(page.component); } + + private getPreferredLanguage () { + const langsAvailable = this.translate.getLangs() + const lang = this.translate.getBrowserLang() + return langsAvailable.indexOf(lang) === -1 ? DEFAULT_LANG : lang + } } interface AppPage {