Angular 角度-ts文件中的ngxTranslate
我需要使用翻译ts文件中的文本字符串 我添加了翻译服务,并尝试做类似的事情Angular 角度-ts文件中的ngxTranslate,angular,Angular,我需要使用翻译ts文件中的文本字符串 我添加了翻译服务,并尝试做类似的事情 constructor( translate: TranslateService ) { translate.get("hello.world").subscribe((text: string) => { console.log(text); // WORK BUT I NEED TO ADD THIS IN ARRAY }); this.idiomasTodos
constructor(
translate: TranslateService
) {
translate.get("hello.world").subscribe((text: string) => {
console.log(text); // WORK BUT I NEED TO ADD THIS IN ARRAY
});
this.idiomasTodos = [
{ id: 1, descripcion: translate.get("spanish") }, //THIS OTHER WAY NO WORK
{ id: 2, descripcion: translate.get("basque") }, //THIS OTHER WAY NO WORK
{ id: 3, descripcion: translate.get("english") } //THIS OTHER WAY NO WORK
];
那么,如何在数组中直接翻译任何文本字符串?而不是
get
方法使用instant
方法
constructor(
translate: TranslateService
) {
this.idiomasTodos = [
{ id: 1, descripcion: translate.instant("spanish") },
{ id: 2, descripcion: translate.instant("basque") },
{ id: 3, descripcion: translate.instant("english") }
];
}
另一种方法是直接在视图中翻译每个单词,而不是在组件中使用
translate
pipe:
- {{idiomasTodo.description | translate}}