X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Flanguage-chooser.component.ts;h=e15aeff201ddc4c9be1c5a92a92fc21504821230;hb=bd45d503e5d007e730f4e81dccd7e7864c9a85cc;hp=43f622dfb1baf5f168de652c1358bc75d6b3a6be;hpb=a30a136c9896c656cab98d2c92cde32c534dc098;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 43f622dfb..e15aeff20 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/core-utils/i18n' @Component({ selector: 'my-language-chooser', @@ -11,11 +11,14 @@ import { sortBy } from '@app/shared/misc/utils' export class LanguageChooserComponent { @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') } @@ -28,4 +31,11 @@ export class LanguageChooserComponent { 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 + } }