@ngx-translate/core’的使用(ionic+angular)
增加语言文件:
日文语言配置文件:
{
"TITLE": "Hello sir",
"TITLE_2": "Hello {{value}}",
"description": "Ooohh .... did you just translate this text ?",
"tabs": {
"manual": "マニュアル",
},
"filter":{
"all": "すべて",
},
"step":{
"title": "ステップ編集",
},
"editor":{
"title": "編集者",
"a": ""
},
"seg":{
"user": "ユーザー",
},
"settings":{
"user":"ユーザー",
"a":""
},
"newPs":{
"oldps": "旧パスワード",
"a": ""
},
"reader":{
"title": "閲覧者",
"a": ""
},
"learn":{
"title": "閲覧/プレビュー",
"a": ""
},
"in_line":{
"title": "内部リンク追加",
},
"out_line":{
"title": "外部リンク追加",
},
"cover":{
"author": "作成者を入力しましょう",
},
"history":{
"today":"今日",
}
}
中文语言配置文件
{
"TITLE": "Hello sir",
"TITLE_2": "Hello {{value}}",
"description": "Ooohh .... did you just translate this text ?",
"tabs": {
"manual": "手册",
},
"filter":{
"all": "所有",
},
"step":{
"title": "步骤编辑",
},
"editor":{
"title": "编辑者",
"a": ""
},
"reader":{
"title": "阅览者",
"a": ""
},
"learn":{
"title": "阅览/预览",
} ,
"settings":{
"a":""
},
"seg":{
"all":"所有",
},
"newPs":{
"oldps": "请输入旧密码",
},
"in_line":{
"title": "添加内部链接",
},
"out_line":{
"title": "外部链接添加",
},
"cover":{
"author": "输入作者",
},
"history":{
"today":"今天",
}
}
全局使用语言配置
import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
constructor(private translate: TranslateService) {
this.init();
}
init() {
this.translate.setDefaultLang('jp');
this.translate.use('jp');});
}
}
引用(.ts)
import { TranslateService } from '@ngx-translate/core';
constructor(
public trans: TranslateService
) { }
text: this.trans.instant(['step.pic_cam'])['step.pic_cam'],
引用(.html)
<ion-title class="t_title">{{ 'step.tool_title' | translate }}</ion-title>