]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
fedb6e181da7fe6e28c800ded58e084bf22e20ed
[ceph-ci.git] /
1 import { Component, Input, OnInit } from '@angular/core';
2
3 import * as _ from 'lodash';
4
5 import { LanguageService } from '../../services/language.service';
6 import { SupportedLanguages } from './supported-languages.enum';
7
8 @Component({
9   selector: 'cd-language-selector',
10   templateUrl: './language-selector.component.html',
11   styleUrls: ['./language-selector.component.scss']
12 })
13 export class LanguageSelectorComponent implements OnInit {
14   @Input()
15   isDropdown = true;
16
17   supportedLanguages: Record<string, any> = {};
18   selectedLanguage: string;
19
20   constructor(private languageService: LanguageService) {}
21
22   ngOnInit() {
23     this.selectedLanguage = this.languageService.getLocale();
24
25     this.languageService.getLanguages().subscribe((langs) => {
26       this.supportedLanguages = _.pick(SupportedLanguages, langs) as Object;
27     });
28   }
29
30   /**
31    * Jest is being more restricted regarding spying on the reload method.
32    * This will allow us to spyOn this method instead.
33    */
34   reloadWindow() {
35     window.location.reload();
36   }
37
38   changeLanguage(lang: string) {
39     this.languageService.setLocale(lang);
40     this.reloadWindow();
41   }
42 }