PeerTube/client/src/app/menu/language-chooser.component.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-06-23 14:10:17 +02:00
import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'
import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
2020-08-06 14:58:01 +02:00
import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/core-utils/i18n'
2018-06-28 13:59:48 +02:00
@Component({
selector: 'my-language-chooser',
templateUrl: './language-chooser.component.html',
styleUrls: [ './language-chooser.component.scss' ]
})
export class LanguageChooserComponent {
2019-07-24 16:05:59 +02:00
@ViewChild('modal', { static: true }) modal: ElementRef
2018-06-28 13:59:48 +02:00
languages: { id: string, label: string, iso: string }[] = []
2018-06-28 13:59:48 +02:00
constructor (
private modalService: NgbModal,
@Inject(LOCALE_ID) private localeId: string
) {
2018-08-27 11:20:06 +02:00
const l = Object.keys(I18N_LOCALES)
2021-08-17 14:42:53 +02:00
.map(k => ({ id: k, label: I18N_LOCALES[k], iso: getShortLocale(k) }))
2018-08-27 11:20:06 +02:00
this.languages = sortBy(l, 'label')
2018-06-28 13:59:48 +02:00
}
show () {
this.modalService.open(this.modal, { centered: true })
2018-06-28 13:59:48 +02:00
}
buildLanguageLink (lang: { id: string }) {
return window.location.origin + '/' + lang.id
}
getCurrentLanguage () {
const english = 'English'
const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId)
2020-03-11 16:41:38 +01:00
if (locale) return I18N_LOCALES[locale] || english
return english
}
2018-06-28 13:59:48 +02:00
}