]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core' |
2 | import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers' | |
63347a0f | 3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
bd45d503 | 4 | import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/core-utils/i18n' |
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 { | |
f36da21e | 12 | @ViewChild('modal', { static: true }) modal: ElementRef |
8afc19a6 | 13 | |
0c23363a | 14 | languages: { id: string, label: string, iso: string }[] = [] |
8afc19a6 | 15 | |
d3217560 RK |
16 | constructor ( |
17 | private modalService: NgbModal, | |
18 | @Inject(LOCALE_ID) private localeId: string | |
19 | ) { | |
a9155ee6 | 20 | const l = Object.keys(I18N_LOCALES) |
9df52d66 | 21 | .map(k => ({ id: k, label: I18N_LOCALES[k], iso: getShortLocale(k) })) |
a9155ee6 C |
22 | |
23 | this.languages = sortBy(l, 'label') | |
8afc19a6 C |
24 | } |
25 | ||
26 | show () { | |
24e7916c | 27 | this.modalService.open(this.modal, { centered: true }) |
8afc19a6 C |
28 | } |
29 | ||
30 | buildLanguageLink (lang: { id: string }) { | |
31 | return window.location.origin + '/' + lang.id | |
32 | } | |
33 | ||
d3217560 RK |
34 | getCurrentLanguage () { |
35 | const english = 'English' | |
36 | const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) | |
111fdc26 | 37 | |
d3217560 RK |
38 | if (locale) return I18N_LOCALES[locale] || english |
39 | return english | |
40 | } | |
8afc19a6 | 41 | } |