Angular 翻译不读取里面的变量 json
Angular translate doen't read variables inside json
我的控制器中有一个通知数组,然后在不同的事件中将一个字符串(翻译键)推入其中。例如,我的 json:
{
'orderAccepted': 'Your order with id #{{order.id}} was accepted'
}
我有一个值 order['id'],但在视图中它显示 'Your order with id # was accepted'。其他没有价值的翻译工作。我的 ng-repeat:
<ul>
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index">{{notification | translate}}</li>
</ul>
您应该弄清楚如何为您的通知构造一个对象数组,其中包含翻译键和任何其他信息。然后你应该像这样添加你想要显示的变量:
{
'orderAccepted': 'Your order with id #{{orderId}} was accepted'
}
和html:
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index">
{{notification.translationKey | translate:'{ orderId: notification.orderId}'}}
</li>
或者尝试使用翻译作为指令:
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index"
translate="{{notification.translationKey}}"
translate-values="{ orderId: notification.orderId }"></li>
您只需要弄清楚通知对象的外观以及存储订单 ID 的位置。
见docs
我的控制器中有一个通知数组,然后在不同的事件中将一个字符串(翻译键)推入其中。例如,我的 json:
{
'orderAccepted': 'Your order with id #{{order.id}} was accepted'
}
我有一个值 order['id'],但在视图中它显示 'Your order with id # was accepted'。其他没有价值的翻译工作。我的 ng-repeat:
<ul>
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index">{{notification | translate}}</li>
</ul>
您应该弄清楚如何为您的通知构造一个对象数组,其中包含翻译键和任何其他信息。然后你应该像这样添加你想要显示的变量:
{
'orderAccepted': 'Your order with id #{{orderId}} was accepted'
}
和html:
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index">
{{notification.translationKey | translate:'{ orderId: notification.orderId}'}}
</li>
或者尝试使用翻译作为指令:
<li data-ng-repeat="notification in notifications | limitTo: -5 track by $index"
translate="{{notification.translationKey}}"
translate-values="{ orderId: notification.orderId }"></li>
您只需要弄清楚通知对象的外观以及存储订单 ID 的位置。
见docs