moya-locale.component.ts
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Component, OnInit } from '@angular/core';
import {DEFAULT_LOCALE, ENGLISH, FINNISH, LocaleService, SWEDISH} from './locale.service';
@Component({
selector: 'moya-locale',
templateUrl: './moya-locale.component.html',
styleUrls: ['./moya-locale.component.scss']
})
export class MoyaLocaleComponent implements OnInit {
fiSelected = true;
svSelected = true;
enSelected = true;
constructor(private localeService: LocaleService) { }
ngOnInit() {
this.localeService.getUserLocale().subscribe(locale => { this.updateFlagStatus(locale); } );
}
updateFlagStatus(locale: string): void {
if (![ENGLISH, FINNISH, SWEDISH].includes(locale)) {
return;
}
this.fiSelected = this.svSelected = this.enSelected = false;
switch (locale) {
case FINNISH:
this.fiSelected = true;
break;
case ENGLISH:
this.enSelected = true;
break;
case SWEDISH:
this.svSelected = true;
break;
}
}
selectEnglish() {
this.updateFlagStatus(this.localeService.selectLocale(ENGLISH, true));
}
selectFinnish() {
this.updateFlagStatus(this.localeService.selectLocale(FINNISH, true));
}
selectSwedish() {
this.updateFlagStatus(this.localeService.selectLocale(SWEDISH, true));
}
}