👽 Conserver le choix de langue au rechargement de la page - issue #54

This commit is contained in:
tykayn 2020-04-11 17:07:38 +02:00
parent 936110846c
commit acb091802c
2 changed files with 20 additions and 4 deletions

View File

@ -10,7 +10,9 @@ import {mockSuccessVote} from '../config/mocks/mock-success-vote';
import {PollUtilities} from '../config/PollUtilities'; import {PollUtilities} from '../config/PollUtilities';
const LocalstoragePreferences = { const LocalstoragePreferences = {
themeName: 'light-watermelon' themeName: 'light-watermelon',
themeClass: 'theme-light-watermelon',
lang: 'fr',
}; };
/** /**

View File

@ -26,15 +26,29 @@ export class LanguageComponent implements OnInit {
@Inject(DOCUMENT) private document, @Inject(DOCUMENT) private document,
private route: Router) { private route: Router) {
this.translate.setDefaultLang(this.currentLang);
} }
ngOnInit(): void { ngOnInit(): void {
console.log('this.config.preferences', this.config.preferences)
if (this.config.preferences.lang) {
this.switchLanguage(this.config.preferences.lang);
} else {
this.switchLanguage(this.currentLang);
}
} }
switchLanguage(language: string) { switchLanguage(language: string) {
if (this.langsAvailable.includes(language)) {
this.translate.use(language); this.translate.use(language);
this.currentLang = language; this.currentLang = language;
this.config.setPreference('lang', language);
this.translate.setDefaultLang(this.currentLang);
} else {
console.error('this lang is not supported');
}
} }
/** /**