Fix language switching issue

This commit is contained in:
Steven Zou 2017-04-12 17:33:36 +08:00
parent 3171e43e66
commit 7247fe3924
2 changed files with 9 additions and 9 deletions

View File

@ -131,6 +131,7 @@ export class SignInComponent implements AfterViewChecked, OnInit {
let expires: number = expireDays * 3600 * 24 * 1000; let expires: number = expireDays * 3600 * 24 * 1000;
let date = new Date(Date.now() + expires); let date = new Date(Date.now() + expires);
let cookieptions = new CookieOptions({ let cookieptions = new CookieOptions({
path: "/",
expires: date expires: date
}); });
this.cookie.put(remCookieKey, this.signInCredential.principal, cookieptions); this.cookie.put(remCookieKey, this.signInCredential.principal, cookieptions);

View File

@ -7,7 +7,7 @@ import { modalEvents } from '../modal-events.const';
import { SessionUser } from '../../shared/session-user'; import { SessionUser } from '../../shared/session-user';
import { SessionService } from '../../shared/session.service'; import { SessionService } from '../../shared/session.service';
import { CookieService } from 'angular2-cookie/core'; import { CookieService, CookieOptions } from 'angular2-cookie/core';
import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../shared/shared.const'; import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../shared/shared.const';
import { AppConfigService } from '../../app-config.service'; import { AppConfigService } from '../../app-config.service';
@ -44,7 +44,8 @@ export class NavigatorComponent implements OnInit {
this.translate.onLangChange.subscribe(langChange => { this.translate.onLangChange.subscribe(langChange => {
this.selectedLang = langChange.lang; this.selectedLang = langChange.lang;
//Keep in cookie for next use //Keep in cookie for next use
this.cookie.put("harbor-lang", langChange.lang); let opt = new CookieOptions({path: '/', expires: new Date(Date.now() + 3600*1000*24*31)});
this.cookie.put("harbor-lang", langChange.lang, opt);
}); });
if (this.appConfigService.isIntegrationMode()) { if (this.appConfigService.isIntegrationMode()) {
this.appTitle = 'APP_TITLE.VIC'; this.appTitle = 'APP_TITLE.VIC';
@ -126,16 +127,14 @@ export class NavigatorComponent implements OnInit {
//Switch languages //Switch languages
switchLanguage(lang: string): void { switchLanguage(lang: string): void {
let selectedLang: string = enLang;//Default
if (supportedLangs.find(supportedLang => supportedLang === lang.trim())) { if (supportedLangs.find(supportedLang => supportedLang === lang.trim())) {
this.translate.use(lang); selectedLang = lang;
} else { } else {
this.translate.use(enLang);//Use default console.error('Language ' + lang.trim() + ' is not suppoted yet');
//TODO:
console.error('Language ' + lang.trim() + ' is not suppoted');
} }
setTimeout(() => {
window.location.reload(); this.translate.use(selectedLang).subscribe(() => window.location.reload());
}, 500);
} }
//Handle the home action //Handle the home action