aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/app.component.ts
blob: 0d1ce1279a4f368b35b56f91e189c48914a85086 (plain)
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
import { Component, OnInit, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ConfigService, IConfig } from './services/config.service';

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.css']
})

export class AppComponent implements OnInit, OnDestroy {
    private defaultLanguage = 'en';
    public isCollapsed = true;

    constructor(private translate: TranslateService, private configSvr: ConfigService) {
    }

    ngOnInit() {
        this.translate.addLangs(['en', 'fr']);
        this.translate.setDefaultLang(this.defaultLanguage);

        const browserLang = this.translate.getBrowserLang();
        this.translate.use(browserLang.match(/en|fr/) ? browserLang : this.defaultLanguage);

        this.configSvr.Conf$.subscribe((cfg: IConfig) => {
            let lang: string;
            switch (cfg.language) {
                case 'ENG':
                    lang = 'en';
                    break;
                case 'FRA':
                    lang = 'fr';
                    break;
                default:
                    lang = this.defaultLanguage;
            }
            this.translate.use(lang);
        });
    }

    ngOnDestroy(): void {
        // this.aglIdentityService.loginResponse.unsubscribe();
        // this.aglIdentityService.logoutResponse.unsubscribe();
    }
}