aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/language-chooser.component.ts
blob: 3de6a129d356f28156b541a7095be51a7b46349a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Component, ViewChild } from '@angular/core'
import { ModalDirective } from 'ngx-bootstrap/modal'
import { I18N_LOCALES } from '../../../../shared'

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

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

  constructor () {
    this.languages = Object.keys(I18N_LOCALES)
      .map(k => ({ id: k, label: I18N_LOCALES[k] }))
  }

  show () {
    this.modal.show()
  }

  hide () {
    this.modal.hide()
  }

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

}