doshprompt / angular-localization

angularjs localization done right.
http://doshprompt.github.io/angular-localization
MIT License
159 stars 78 forks source link

ng-pluralization and usage with languages of different numbers of plural modes #34

Open brycecr opened 9 years ago

brycecr commented 9 years ago

I was thinking about ng-pluralize and angular-localization in the case where we have a phrase that is translated into two languages with different number of plural modes.

E.g., in english, we just want to use the simple rule one / other:

<ng-pluralize data-count="numCount" data-when="{ '1': '{{ 'one': '{{ plurals.one | i18n }}', 'other': '{{ plurals.other | i18n }}' }" ></ng-pluralize>

But if I then want translate to, say, russian, then the number of rules i need changes to 4 to something like:

<ng-pluralize data-count="numCount" data-when="{ '1': '{{ 'one': '{{ plurals.one | i18n }}', 'other': '{{ plurals.other | i18n }}', 'few': {{ plurals.few | i18n }}, 'many':'{{ plurals.many | i18n }}' }" ></ng-pluralize>

However, I've already hardcoded the number of rules by setting them in the when attribute as such, so just translating the one and other options from the english version isn't enough to implement the above.

So, what I'd really like to so is something like:

<span data-count="numCount" data-i18n-plural="pluralMsg"></span>

And then provide, in the translation for pluralMsg, a plural-sensitive string. This is the way it's handled in ICU format (e.g. formatjs and I can see why -- it makes a lot more sense to have the translator figure out the correct pluralization rules in the yaml/json file then to have devs set the plural branching.

This leads me to few questions:

Thanks!

brycecr commented 9 years ago

This is essentially the same as issue #16

thenikso commented 9 years ago

What I do for the moment is something like:

<any i18n="common.key-{{ myCount==1&&'signle'||'plural' }}" data-count="{{ myCount }}">

Which works just fine for a single/plural case avoiding filters.