1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { I18N_LOCALES } from '../../../../shared'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { sortBy } from '@app/shared/misc/utils'
7 selector: 'my-language-chooser',
8 templateUrl: './language-chooser.component.html',
9 styleUrls: [ './language-chooser.component.scss' ]
11 export class LanguageChooserComponent {
12 @ViewChild('modal') modal: ElementRef
14 languages: { id: string, label: string }[] = []
16 constructor (private modalService: NgbModal) {
17 const l = Object.keys(I18N_LOCALES)
18 .map(k => ({ id: k, label: I18N_LOCALES[k] }))
20 this.languages = sortBy(l, 'label')
24 this.modalService.open(this.modal)
27 buildLanguageLink (lang: { id: string }) {
28 return window.location.origin + '/' + lang.id