How to use variables in angular translate pluralization?

1k Views Asked by At

I am trying to make the angular translate pluralization work with $scope variables. Everything works fine when the numbers are hard-coded in the HTML, but things get buggy when I am using my model's variables.

For instance, for this translation:

"PLURAL_TEXT": "{N, plural, =0{no results} one{1 result} other{# results} }"

This HTML piece:

{{"PLURAL_TEXT"|translate:"{N:2}"}}

Gives "2 results" which is OK.

But when I write this instead:

{{"PLURAL_TEXT"|translate:"{N:myarray.length}"}}

(where $scope.myarray is a JavaScript array) Then I get "1 result" even though $scope.myarray.length is 5, 0 or whatever.

So my question is how to use the pluralization with variables. All the examples I have found in the doc and elsewhere use hard-coded values. Many thanks!

(btw, I did not try to play with the switchable interpolation approach, with the 3rd parameter of the filter being 'messageformat', as I don't need this level of sophistication, and I believe it's pointless for my issue, but let me know if I am wrong).

0

There are 0 best solutions below