import {Injectable} from '@angular/core';
import {TranslatePipe, TranslateService} from '@ngx-translate/core';

/*********************
 * 国际化
 */
@Injectable()
export class TranslatorService {

  private defaultLanguage: string = 'zh';

  private availablelangs = [
    {code: 'zh', text: '简体中文'},
    {code: 'en', text: 'English'}
  ];

  constructor(public translate: TranslateService) {

    if (!translate.getDefaultLang())
      translate.setDefaultLang(this.defaultLanguage);
    this.useLanguage();
  }

  useLanguage(lang: string = null) {
    this.translate.use(lang || this.translate.getDefaultLang());
  }

  getAvailableLanguages() {
    return this.availablelangs;
  }

}
