moya-locale.component.ts 1.26 KB
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));
  }
}