front end version 2 de framadate, un gestionnaire de sondage
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.3 KiB

import { Component, DoCheck, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Language } from '../../../enums/language.enum';
import { StorageService } from '../../../services/storage.service';
@Component({
selector: 'app-language-selector',
templateUrl: './language-selector.component.html',
styleUrls: ['./language-selector.component.scss'],
})
export class LanguageSelectorComponent implements OnInit, DoCheck {
public currentLang: Language;
public languagesAvailable: string[] = Object.values(Language);
constructor(private translate: TranslateService, private storageService: StorageService) {}
ngOnInit(): void {
const currentBrowserLanguage: Language = this.translate.getBrowserLang().toUpperCase() as Language;
if (this.storageService.language && Object.keys(Language).includes(this.storageService.language)) {
this.currentLang = this.storageService.language;
} else if (Object.keys(Language).includes(currentBrowserLanguage)) {
this.currentLang = currentBrowserLanguage;
} else {
this.currentLang = Language.EN;
}
this.updateLanguage();
}
ngDoCheck(): void {
this.updateLanguage();
}
public updateLanguage(): void {
this.translate.use(this.currentLang.toString().toUpperCase());
this.storageService.language = this.currentLang;
}
}