aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/menu/language-chooser.component.ts
blob: 43f622dfb1baf5f168de652c1358bc75d6b3a6be (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                                                
                                                 
                                                     
                                               






                                                    
                                                         
 
                                                 
 
                                                



                                                                  


           
                                                          






                                                 
import { Component, ElementRef, ViewChild } from '@angular/core'
import { I18N_LOCALES } from '../../../../shared'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { sortBy } from '@app/shared/misc/utils'

@Component({
  selector: 'my-language-chooser',
  templateUrl: './language-chooser.component.html',
  styleUrls: [ './language-chooser.component.scss' ]
})
export class LanguageChooserComponent {
  @ViewChild('modal', { static: true }) modal: ElementRef

  languages: { id: string, label: string }[] = []

  constructor (private modalService: NgbModal) {
    const l = Object.keys(I18N_LOCALES)
                    .map(k => ({ id: k, label: I18N_LOCALES[k] }))

    this.languages = sortBy(l, 'label')
  }

  show () {
    this.modalService.open(this.modal, { centered: true })
  }

  buildLanguageLink (lang: { id: string }) {
    return window.location.origin + '/' + lang.id
  }

}