allow limiting video-comments rss feeds to an account or video channel
[oweals/peertube.git] / client / src / app / menu / language-chooser.component.ts
1 import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'
2 import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/models'
5
6 @Component({
7   selector: 'my-language-chooser',
8   templateUrl: './language-chooser.component.html',
9   styleUrls: [ './language-chooser.component.scss' ]
10 })
11 export class LanguageChooserComponent {
12   @ViewChild('modal', { static: true }) modal: ElementRef
13
14   languages: { id: string, label: string, iso: string }[] = []
15
16   constructor (
17     private modalService: NgbModal,
18     @Inject(LOCALE_ID) private localeId: string
19   ) {
20     const l = Object.keys(I18N_LOCALES)
21                     .map(k => ({ id: k, label: I18N_LOCALES[k] , iso: getShortLocale(k) }))
22
23     this.languages = sortBy(l, 'label')
24   }
25
26   show () {
27     this.modalService.open(this.modal, { centered: true })
28   }
29
30   buildLanguageLink (lang: { id: string }) {
31     return window.location.origin + '/' + lang.id
32   }
33
34   getCurrentLanguage () {
35     const english = 'English'
36     const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId)
37
38     if (locale) return I18N_LOCALES[locale] || english
39     return english
40   }
41 }