沈斌
2018-07-10 fec630978ad9b1ce5caff7dbc74e7d10d43a0970
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
33
34
35
36
37
38
39
40
41
import { Component, Inject } from '@angular/core';
import {
  SettingsService,
  MenuService,
  TitleService,
  ALAIN_I18N_TOKEN,
} from '@delon/theme';
import { I18NService } from '@core/i18n/i18n.service';
 
@Component({
  selector: 'header-i18n',
  template: `
  <nz-dropdown>
    <div nz-dropdown>
      <i class="anticon anticon-edit"></i>
      {{ 'language' | translate}}
      <i class="anticon anticon-down"></i>
    </div>
    <ul nz-menu>
      <li nz-menu-item *ngFor="let item of langs"
        [nzSelected]="item.code === settings.layout.lang"
        (click)="change(item.code)">{{item.text}}</li>
    </ul>
  </nz-dropdown>
  `,
})
export class HeaderI18nComponent {
  langs: any[];
 
  constructor(
    public settings: SettingsService,
    @Inject(ALAIN_I18N_TOKEN) private i18n: I18NService,
  ) {
    this.langs = this.i18n.getLangs();
  }
 
  change(lang: string) {
    this.i18n.use(lang);
    this.settings.setLayout('lang', lang);
  }
}