AngularJS pluralization with angular translate and ng pluralization

I have this code code

<ng-pluralize count="comment.Comment.like_count" when="{'0': {{'LIKES_LIKE' | translate}}, 'one': {{'LIKES_LIKE' | translate}}, 'other': '{{'LIKES_LIKES' | translate}}}"> </ng-pluralize> 

but I canโ€™t figure out how to format the string so that it actually parses the strings of the string I like using the translation filter, so that the ng-pluralize directive gets the syntactic syntax string.

Error message:

Error: [$ parse: lexerr] Lexer error: inexhaustible quote in columns 107-123 ['| translate}}}] into the expression [{'0': {{'LIKES_LIKE' | translate}}, 'one': {{'LIKES_LIKE' | translate}}, 'other': '{{' LIKES_LIKE '| transfer}}}].

I understand well what I mean, but I cannot figure out how to make it work. Any ideas?

+5
source share
2 answers

I searched for the same answer and came up with this solution: Exclude quotes for the translation key with "

 <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> 

or use an ng-int value object (you can also define these values โ€‹โ€‹on your controller)

 <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> 

To interpolate by counter value you can use

 <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> 

Where LIKES_LIKES = "{{count}} like"

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

+20
source

It seems that the first quote is not destroyed here: '{{'LIKES_LIKES'

Offer to remove it.

+2
source

Source: https://habr.com/ru/post/1208187/


All Articles