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