angular2+ 国际化

本实例是利用啦Ng Alain 构造的项目

1:html中

<button nz-button nzType="primary" nzGhost *ngIf="addBtn" (click)="add()"><i class="anticon anticon-plus"></i> <span>{{translate('Add')}}</span></button>

2:ts里

import {I18NService} from '@core/i18n/i18n.service';
constructor(public tsServ: I18NService, private api: ConfigService) { }
translate(key) {
  return this.tsServ.fanyi(key);
}  此处是使用I18NService里的翻译函数

3:en.json &&zh-CN.json(中文简体)

"Add": "Add"
"Add": "添加"

猜你喜欢

转载自blog.csdn.net/qq_38643776/article/details/81207114