]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, ViewChild } from '@angular/core' |
8afc19a6 | 2 | import { I18N_LOCALES } from '../../../../shared' |
63347a0f | 3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
a9155ee6 | 4 | import { sortBy } from '@app/shared/misc/utils' |
8afc19a6 C |
5 | |
6 | @Component({ | |
7 | selector: 'my-language-chooser', | |
8 | templateUrl: './language-chooser.component.html', | |
9 | styleUrls: [ './language-chooser.component.scss' ] | |
10 | }) | |
11 | export class LanguageChooserComponent { | |
63347a0f | 12 | @ViewChild('modal') modal: ElementRef |
8afc19a6 | 13 | |
63347a0f | 14 | languages: { id: string, label: string }[] = [] |
8afc19a6 | 15 | |
63347a0f | 16 | constructor (private modalService: NgbModal) { |
a9155ee6 C |
17 | const l = Object.keys(I18N_LOCALES) |
18 | .map(k => ({ id: k, label: I18N_LOCALES[k] })) | |
19 | ||
20 | this.languages = sortBy(l, 'label') | |
8afc19a6 C |
21 | } |
22 | ||
23 | show () { | |
63347a0f | 24 | this.modalService.open(this.modal) |
8afc19a6 C |
25 | } |
26 | ||
27 | buildLanguageLink (lang: { id: string }) { | |
28 | return window.location.origin + '/' + lang.id | |
29 | } | |
30 | ||
31 | } |