]>
Commit | Line | Data |
---|---|---|
d3217560 | 1 | import { Component, ElementRef, ViewChild, Inject, LOCALE_ID } 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' |
d3217560 RK |
5 | import { getCompleteLocale } from '@shared/models/i18n' |
6 | import { isOnDevLocale, getDevLocale } from '@app/shared/i18n/i18n-utils' | |
8afc19a6 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-language-chooser', | |
10 | templateUrl: './language-chooser.component.html', | |
11 | styleUrls: [ './language-chooser.component.scss' ] | |
12 | }) | |
13 | export class LanguageChooserComponent { | |
f36da21e | 14 | @ViewChild('modal', { static: true }) modal: ElementRef |
8afc19a6 | 15 | |
63347a0f | 16 | languages: { id: string, label: string }[] = [] |
8afc19a6 | 17 | |
d3217560 RK |
18 | constructor ( |
19 | private modalService: NgbModal, | |
20 | @Inject(LOCALE_ID) private localeId: string | |
21 | ) { | |
a9155ee6 C |
22 | const l = Object.keys(I18N_LOCALES) |
23 | .map(k => ({ id: k, label: I18N_LOCALES[k] })) | |
24 | ||
25 | this.languages = sortBy(l, 'label') | |
8afc19a6 C |
26 | } |
27 | ||
28 | show () { | |
24e7916c | 29 | this.modalService.open(this.modal, { centered: true }) |
8afc19a6 C |
30 | } |
31 | ||
32 | buildLanguageLink (lang: { id: string }) { | |
33 | return window.location.origin + '/' + lang.id | |
34 | } | |
35 | ||
d3217560 RK |
36 | getCurrentLanguage () { |
37 | const english = 'English' | |
38 | const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) | |
111fdc26 | 39 | |
d3217560 RK |
40 | if (locale) return I18N_LOCALES[locale] || english |
41 | return english | |
42 | } | |
8afc19a6 | 43 | } |