import { Component, Inject, Input, ChangeDetectionStrategy } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import { SettingsService, ALAIN_I18N_TOKEN } from '@delon/theme'; import { I18NService } from '@core'; @Component({ selector: 'header-i18n', template: `
{{ 'menu.lang' | translate}}
`, changeDetection: ChangeDetectionStrategy.OnPush }) export class HeaderI18nComponent { langs: any[]; @Input() showLang = true; constructor( public settings: SettingsService, @Inject(ALAIN_I18N_TOKEN) private i18n: I18NService, @Inject(DOCUMENT) private doc: any, ) { this.langs = this.i18n.getLangs(); } change(lang: string) { const spinEl = this.doc.createElement('div'); spinEl.setAttribute('class', `page-loading ant-spin ant-spin-lg ant-spin-spinning`); spinEl.innerHTML = ``; this.doc.body.appendChild(spinEl); this.i18n.use(lang); this.settings.setLayout('lang', lang); setTimeout(() => this.doc.location.reload()); } }