]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/menu/language-chooser.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / menu / language-chooser.component.ts
CommitLineData
67ed6552
C
1import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'
2import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
63347a0f 3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
54909304 4import { objectKeysTyped } from '@shared/core-utils'
bd45d503 5import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/core-utils/i18n'
8afc19a6
C
6
7@Component({
8 selector: 'my-language-chooser',
9 templateUrl: './language-chooser.component.html',
10 styleUrls: [ './language-chooser.component.scss' ]
11})
12export class LanguageChooserComponent {
f36da21e 13 @ViewChild('modal', { static: true }) modal: ElementRef
8afc19a6 14
0c23363a 15 languages: { id: string, label: string, iso: string }[] = []
8afc19a6 16
d3217560
RK
17 constructor (
18 private modalService: NgbModal,
19 @Inject(LOCALE_ID) private localeId: string
20 ) {
54909304
C
21 const l = objectKeysTyped(I18N_LOCALES)
22 .map(k => ({ id: k, label: I18N_LOCALES[k], iso: getShortLocale(k) }))
a9155ee6
C
23
24 this.languages = sortBy(l, 'label')
8afc19a6
C
25 }
26
27 show () {
24e7916c 28 this.modalService.open(this.modal, { centered: true })
8afc19a6
C
29 }
30
31 buildLanguageLink (lang: { id: string }) {
32 return window.location.origin + '/' + lang.id
33 }
34
d3217560
RK
35 getCurrentLanguage () {
36 const english = 'English'
37 const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId)
111fdc26 38
54909304 39 if (locale) return I18N_LOCALES[locale as keyof typeof I18N_LOCALES] || english
d3217560
RK
40 return english
41 }
8afc19a6 42}