]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/menu/language-chooser.component.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / menu / language-chooser.component.ts
index 4a6e4c75ae4b044be8afd83ebd645c90e312b1d4..e15aeff201ddc4c9be1c5a92a92fc21504821230 100644 (file)
@@ -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,21 +11,31 @@ 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')
   }
 
   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
+  }
 }