angular-localization icon indicating copy to clipboard operation
angular-localization copied to clipboard

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

Open brycecr opened this issue 9 years ago • 2 comments

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:

  • Am I correct in saying this is a problem?
  • What is the best way to handle this in ngLocalize currently?
  • If the answer to the above isn't the way we want this to work, how can we change ngLocalize to handle this better?

Thanks!

brycecr avatar Mar 02 '15 19:03 brycecr

This is essentially the same as issue #16

brycecr avatar Mar 11 '15 21:03 brycecr

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.

thenikso avatar Jun 23 '15 08:06 thenikso