2018-08-09 14:55:06 +02:00
|
|
|
import { Component, ElementRef, ViewChild } from '@angular/core'
|
2018-06-28 13:59:48 +02:00
|
|
|
import { I18N_LOCALES } from '../../../../shared'
|
2018-08-09 14:55:06 +02:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
2018-08-27 11:20:06 +02:00
|
|
|
import { sortBy } from '@app/shared/misc/utils'
|
2018-06-28 13:59:48 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-language-chooser',
|
|
|
|
templateUrl: './language-chooser.component.html',
|
|
|
|
styleUrls: [ './language-chooser.component.scss' ]
|
|
|
|
})
|
|
|
|
export class LanguageChooserComponent {
|
2019-07-24 16:05:59 +02:00
|
|
|
@ViewChild('modal', { static: true }) modal: ElementRef
|
2018-06-28 13:59:48 +02:00
|
|
|
|
2018-08-09 14:55:06 +02:00
|
|
|
languages: { id: string, label: string }[] = []
|
2018-06-28 13:59:48 +02:00
|
|
|
|
2018-08-09 14:55:06 +02:00
|
|
|
constructor (private modalService: NgbModal) {
|
2018-08-27 11:20:06 +02:00
|
|
|
const l = Object.keys(I18N_LOCALES)
|
|
|
|
.map(k => ({ id: k, label: I18N_LOCALES[k] }))
|
|
|
|
|
|
|
|
this.languages = sortBy(l, 'label')
|
2018-06-28 13:59:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
show () {
|
2020-02-05 20:54:37 +01:00
|
|
|
this.modalService.open(this.modal, { centered: true })
|
2018-06-28 13:59:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buildLanguageLink (lang: { id: string }) {
|
|
|
|
return window.location.origin + '/' + lang.id
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|