问题描述
我正在尝试使用 json 文件在我的应用程序中实现 i18n 进行语言翻译。我能够成功翻译静态文本。但我无法翻译动态文本和使用 *ngFor 循环显示在数组中的文本。 前任: 我正在使用数组通过 *ngFor 在仪表板中显示一些列表
let tempIcons = [{
id: 1,name: test,iconName: resultset,iconDesc: usesd in home page
},{
id: 2,name: test12,iconName: resultset23,iconDesc: usesd in contact page
},{
id: 3,name: test23,iconDesc: usesd in about us page
}]
此外,我想更改从后端 api 服务获取的动态文本的语言。谁能给我举个例子。
我正在使用带有 i18n 的 Angular 8。
提前致谢
解决方法
像这样使用:
<div *ngFor="let item of tempIcons">
{{'TRANSLATEPATH.' + item.name.toUpperCase() | translate}}
</div>