X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Flanguage-chooser.component.ts;h=3e89f72b8461a27c831b0950fadf9bb5ad2ad215;hb=0579dee3b29e301838387f53b91b58bff2ffb19a;hp=8eb84673ea08242b3d6119f9c514e7378ff1151c;hpb=a9155ee6dc632e860784c0c9969b594b80355276;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/menu/language-chooser.component.ts b/client/src/app/menu/language-chooser.component.ts index 8eb84673e..3e89f72b8 100644 --- a/client/src/app/menu/language-chooser.component.ts +++ b/client/src/app/menu/language-chooser.component.ts @@ -1,7 +1,7 @@ -import { Component, ElementRef, ViewChild } from '@angular/core' -import { I18N_LOCALES } from '../../../../shared' +import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core' +import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { sortBy } from '@app/shared/misc/utils' +import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/models' @Component({ selector: 'my-language-chooser', @@ -9,23 +9,33 @@ import { sortBy } from '@app/shared/misc/utils' styleUrls: [ './language-chooser.component.scss' ] }) export class LanguageChooserComponent { - @ViewChild('modal') modal: ElementRef + @ViewChild('modal', { static: true }) modal: ElementRef - languages: { id: string, label: string }[] = [] + languages: { id: string, label: string, iso: string }[] = [] - constructor (private modalService: NgbModal) { + constructor ( + private modalService: NgbModal, + @Inject(LOCALE_ID) private localeId: string + ) { const l = Object.keys(I18N_LOCALES) - .map(k => ({ id: k, label: I18N_LOCALES[k] })) + .map(k => ({ id: k, label: I18N_LOCALES[k] , iso: getShortLocale(k) })) this.languages = sortBy(l, 'label') } show () { - this.modalService.open(this.modal) + 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 + } }