AngularJS使用angular-translate和ng-pluralize进行复数化

5 internationalization angularjs angularjs-ng-pluralize

我有这段代码

<ng-pluralize count="comment.Comment.like_count"
    when="{'0': {{'LIKES_LIKE' | translate}},
        'one': {{'LIKES_LIKE' | translate}},
    'other': '{{'LIKES_LIKES' | translate}}}">
</ng-pluralize>
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何格式化字符串,以便它实际解析翻译过滤器喜欢的字符串,以便ng-pluralize指令接收解析的语言字符串.

错误消息是这样的:

错误:[$ parse:lexerr] Lexer错误:第107-123列['|]的未终止引用 翻译}}}]在表达式[{'0':{{'LIKES_LIKE'| 翻译}},'one':{{'LIKES_LIKE'| 翻译}},'其他':'{{'LIKES_LIKE'| 翻译}}}].

我很清楚我的意思,但我无法弄清楚如何让它发挥作用.有任何想法吗?

Ste*_*ren 20

我正在寻找相同的答案,并提出这个解决方案:用"""转义翻译键的引号

<ng-pluralize count="comment.Comment.like_count"
    when="{'0': '{{&quot;LIKES_LIKE&quot; | translate}}',
        'one': '{{&quot;LIKES_LIKE&quot; | translate}}',
        'other': '{{&quot;LIKES_LIKES&quot; | translate}}'}">
</ng-pluralize>
Run Code Online (Sandbox Code Playgroud)

或者使用ng-int值对象(您也可以在控制器上定义这些值)

<ng-pluralize count="comment.Comment.like_count"
    ng-init="likes_like='LIKES_LIKE'; likes_likes='LIKES_LIKE'"
    when="{'0': '{{likes_like | translate}}',
        'one': '{{likes_like | translate}}',
        'other': '{{likes_likes | translate}}'}">
</ng-pluralize>
Run Code Online (Sandbox Code Playgroud)

对于teh计数值的插值,您可以使用

<ng-pluralize count="comment.Comment.like_count"
    when="{'0': '{{LIKES_LIKE | translate}}',
        'one': '{{LIKES_LIKE | translate}}',
        'other': '{{LIKES_LIKES | translate:{count : comment.Comment.like_count} }}'}">
</ng-pluralize>
Run Code Online (Sandbox Code Playgroud)

其中LIKES_LIKES ="{{count}}喜欢"

http://plnkr.co/edit/TdBPfhqMGuxtWDg28lAV?p=preview


bcr*_*bcr 2

看起来这里的第一句话没有结束:'{{'LIKES_LIKES'

建议删除它。