X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Flanguage-chooser.component.ts;h=c9b775921d18346f8a70c5e8756052806e5b21db;hb=d6d951ddc0c492f3261065b5dcb4df0534d252fc;hp=3de6a129d356f28156b541a7095be51a7b46349a;hpb=8afc19a6121569da054462c7cb351a3f13030a32;p=oweals%2Fpeertube.git diff --git a/client/src/app/menu/language-chooser.component.ts b/client/src/app/menu/language-chooser.component.ts index 3de6a129d..c9b775921 100644 --- a/client/src/app/menu/language-chooser.component.ts +++ b/client/src/app/menu/language-chooser.component.ts @@ -1,6 +1,9 @@ -import { Component, ViewChild } from '@angular/core' -import { ModalDirective } from 'ngx-bootstrap/modal' -import { I18N_LOCALES } from '../../../../shared' +import { Component, ElementRef, ViewChild, Inject, LOCALE_ID } from '@angular/core' +import { I18N_LOCALES, getShortLocale } from '../../../../shared' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { sortBy } from '@app/shared/misc/utils' +import { getCompleteLocale } from '@shared/models/i18n' +import { isOnDevLocale, getDevLocale } from '@app/shared/i18n/i18n-utils' @Component({ selector: 'my-language-chooser', @@ -8,25 +11,33 @@ import { I18N_LOCALES } from '../../../../shared' styleUrls: [ './language-chooser.component.scss' ] }) export class LanguageChooserComponent { - @ViewChild('modal') modal: ModalDirective + @ViewChild('modal', { static: true }) modal: ElementRef - languages: { [ id: string ]: string }[] = [] + languages: { id: string, label: string, iso: string }[] = [] - constructor () { - this.languages = Object.keys(I18N_LOCALES) - .map(k => ({ id: k, label: I18N_LOCALES[k] })) - } + constructor ( + private modalService: NgbModal, + @Inject(LOCALE_ID) private localeId: string + ) { + const l = Object.keys(I18N_LOCALES) + .map(k => ({ id: k, label: I18N_LOCALES[k] , iso: getShortLocale(k) })) - show () { - this.modal.show() + this.languages = sortBy(l, 'label') } - hide () { - this.modal.hide() + show () { + this.modalService.open(this.modal, { centered: true }) } 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 + } }