]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/menu/language-chooser.component.ts
Add lang attribute in languages list menu
[github/Chocobozzz/PeerTube.git] / client / src / app / menu / language-chooser.component.ts
CommitLineData
d3217560 1import { Component, ElementRef, ViewChild, Inject, LOCALE_ID } from '@angular/core'
0c23363a 2import { I18N_LOCALES, getShortLocale } from '../../../../shared'
63347a0f 3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
a9155ee6 4import { sortBy } from '@app/shared/misc/utils'
d3217560
RK
5import { getCompleteLocale } from '@shared/models/i18n'
6import { 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})
13export class LanguageChooserComponent {
f36da21e 14 @ViewChild('modal', { static: true }) modal: ElementRef
8afc19a6 15
0c23363a 16 languages: { id: string, label: string, iso: string }[] = []
8afc19a6 17
d3217560
RK
18 constructor (
19 private modalService: NgbModal,
20 @Inject(LOCALE_ID) private localeId: string
21 ) {
a9155ee6 22 const l = Object.keys(I18N_LOCALES)
0c23363a 23 .map(k => ({ id: k, label: I18N_LOCALES[k] , iso: getShortLocale(k)}))
a9155ee6
C
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}