简体   繁体   English

Angular5-ngx将Pharse值从json转换为lang.json

[英]Angular5 - ngx-translate Pharse value from json to lang.json

Is it possible to pharse data from a item.json to the lang.json? 是否可以将数据从item.json映射到lang.json? I tryed in this way but didnt work: 我以这种方式尝试了但没有成功:

item.json item.json

[
    {
        "id": 1,
        "name": "abilities.strength-plus, {{value: 5}}"
    }
]

lang.json (en) lang.json(en)

{
    "abilities": {
        "strength-plus": "Strength +{{value}}"
    }
}

And tryed to output it in HTML: 并尝试将其输出为HTML:

<ul>
    <li class="list-title">Abilities</li>
    <li *ngFor="let abilitie of abilities">
        <div [innerHTML]="abilitie.name | translate"></div>
    </li>
</ul>

The result is that he just output: abilities.strength-plus, {{value: 5}} 结果是他只输出: abilities.strength-plus, {{value: 5}}

Any idea what im doing wrong? 知道我在做什么错吗? Without Data this way works fine. 如果没有数据,这种方式可以正常工作。

I think it would work if you pulled out the object with the replace data in your item.json and then provided that as the data for ngx-translate. 我认为,如果您在item.json使用替换数据拔出对象,然后将其作为ngx-translate的数据提供,则它将起作用。

item.json item.json

[
    {
        "id": 1,
        "name": "abilities.strength-plus",
        "data": { "value": 5 }
    }
]

html template html模板

<ul>
    <li class="list-title">Abilities</li>
    <li *ngFor="let abilitie of abilities">
        <div [innerHTML]="abilitie.name | translate:abilitie.data"></div>
    </li>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM