【发布时间】:2020-10-08 07:08:45
【问题描述】:
在 ngx-translate 方面需要帮助 在组件 html 中有
{{data.value | translate}}
在ts中
data = {value: 'foo.bar'}
在 i18n en.json 中
"foo": {
"bar": "hello"
}
我在视图中看到的是“foo.bar”,而不是“hello”。
【问题讨论】:
标签: angular ngx-translate
在 ngx-translate 方面需要帮助 在组件 html 中有
{{data.value | translate}}
在ts中
data = {value: 'foo.bar'}
在 i18n en.json 中
"foo": {
"bar": "hello"
}
我在视图中看到的是“foo.bar”,而不是“hello”。
【问题讨论】:
标签: angular ngx-translate
如果您想直接在 Html 中使用,请执行以下操作
{{'foo.bar' | translate}}
参考下面的链接,看看<h2>{{ 'HOME.TITLE' | translate }}</h2> 是如何翻译的
https://stackblitz.com/github/ngx-translate/example?file=src%2Fapp%2Fapp.component.ts
如果您想翻译 TS 中的变量,则可以使用 translate.get 和 translate.stream 方法,如下所示
在 TS 中:
let value = translate.get('foo.bar').subscribe((res: string) => {
return res;
});
在 HTML 中
{{value}}
【讨论】: