All files / src/app app.component.ts

53.33% Statements 8/15
0% Branches 0/2
33.33% Functions 2/6
50% Lines 7/14
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 54 55 56 57 58 59 60 61 62 63 64                            1x   4x 4x                 4x 4x     4x             1x                                                    
import { Component, isDevMode, OnInit } from '@angular/core';
import { LocalStorage } from '@ngx-pwa/local-storage';
import { TranslateService } from '@ngx-translate/core';
import { NgxConfigureService } from 'ngx-configure';
import { version } from '../../package.json';
 
 
 
 
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
 
    public curLanguage = 'en';
    public version: string = version;
 
 
	/**
     * Costructor of component
     * @param translate Ngx Translate service
	 * @param localStorage Local service for data
     */
	constructor(
		private translate: TranslateService,
        private localStorage: LocalStorage,
        configService: NgxConfigureService
	) {
		translate.setDefaultLang(configService.config.language);
	}
 
	/**
	 * Run component initialization tasks:  load orders
	 */
	ngOnInit(): void {
		this.localStorage.getItem('language').subscribe((language: string) => {
			if (language) {
				this.useLanguage(language);
			} else {
				this.useLanguage(this.curLanguage);
			}
		});
    }
 
	/**
	 * Switch interface language
	 * @param language Language to use
	 */
	useLanguage(language: string): void {
		this.translate.use(language);
		this.curLanguage = language;
		this.localStorage.setItem('language', language).subscribe(() => {});
	}
 
	/**
	 * Return whether program is in development mode
	 */
	get isDevMode(): boolean {
		return isDevMode();
	}
}