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

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Component, ElementRef, ViewChild, Inject, LOCALE_ID } from '@angular/core'
2018-06-28 13:59:48 +02:00
import { I18N_LOCALES } from '../../../../shared'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
2018-08-27 11:20:06 +02:00
import { sortBy } from '@app/shared/misc/utils'
import { getCompleteLocale } from '@shared/models/i18n'
import { isOnDevLocale, getDevLocale } from '@app/shared/i18n/i18n-utils'
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 }[] = []
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)
.map(k => ({ id: k, label: I18N_LOCALES[k] }))
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)
if (locale) return I18N_LOCALES[locale] || english
return english
}
2018-06-28 13:59:48 +02:00
}