]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
e03c46ec914ab2009ddf73ade936513c0e61e88e
[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   allLanguages = SupportedLanguages;
18   supportedLanguages: Record<string, any> = {};
19   selectedLanguage: string;
20
21   constructor(private languageService: LanguageService) {}
22
23   ngOnInit() {
24     this.selectedLanguage = this.languageService.getLocale();
25
26     this.languageService.getLanguages().subscribe((langs) => {
27       this.supportedLanguages = _.pick(SupportedLanguages, langs) as Object;
28     });
29   }
30
31   /**
32    * Jest is being more restricted regarding spying on the reload method.
33    * This will allow us to spyOn this method instead.
34    */
35   reloadWindow() {
36     window.location.reload();
37   }
38
39   changeLanguage(lang: string) {
40     this.languageService.setLocale(lang);
41     this.reloadWindow();
42   }
43 }