lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 30 forks source link

Can't combine plural and select #43

Closed bentaly closed 5 years ago

bentaly commented 5 years ago

I have an angular app using your library.

my json lookup contains: "markThing": "Mark thing{count, plural, =0{s} one{} other{s}} as {status, select, UNREAD{unread} READ{read} CLOSED{closed}}"

I have an object like this: this.translations = { count: 2, status: 'CLOSED' };

and in my html:

{{'markThing' | translate:translations}}

But it doesn't work. I can use select on its own, and plural on it's own, but combining fails.

Related stack overflow post

lemoinem commented 5 years ago

Hello,

What do you mean "it doesn't work"? Do you have an error message? If not, what is shown? Have you tried some other solutions? If yes, what have you tried and what did you get?

Have you double check the format of your string? For example https://format-message.github.io/icu-message-format-for-translators/editor.html is usually a good start.

Side-note: unless you actually have a special case for 0 (or 1), it's better to only use keywords for your plural selectors (in your case, one and other), and let messageformat take care of the pluralization rules. In your case, messageformat is already aware that 0, in english, should fall in the other case and not one. The comprehensive list of rules applied by messageformat per language is available here: https://unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html

bentaly commented 5 years ago

Hi thanks for the reply.

The link was very helpful, it pointed out that the select required an other option, which I didn't expect as it's not possible in my app.

p.s. thanks for the tips on =0!

lemoinem commented 5 years ago

You're welcome! If your issue is solved, please close it.