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 29 forks source link

Examples how to use #8

Closed web-dave closed 6 years ago

web-dave commented 6 years ago

Hi, Great work dude, I'm fighting with the template, can you provide some examples. I tried to get the point from your tests. but with no luck. short help would be nice.

web-dave commented 6 years ago

OK here is a example how it works for me:

en.json

{
"icu": "{count, plural, =0{No} one{A} other{#}} {count, plural, one{word} other{words}}"
}

Template

<div [translate]="'icu'" [translateParams]="{count: 0}" ></div>
<div [translate]="'icu'" [translateParams]="{count: 1}" ></div>
<div [translate]="'icu'" [translateParams]="{count: 2}" ></div>

Output: No words A word 2 words

lephyrus commented 6 years ago

@web-dave I'm glad you've figured it out. The thing is: MessageFormat provides the syntax for your strings and ngx-translate provides the ways of including them in your app. None of it is implemented in this compiler, it's just the "glue". I've still added an example in the hope it will help others. Thanks for the input.

DerekJDev commented 6 years ago

Can I please get an example an the translations if the count number is dynamic? Meaning that the count number is coming from a variable within the component.

web-dave commented 6 years ago
<div>{{ 'words' | translate:{count: numWords} }}</div>

Po file msgid "words" msgstr "{count, plural, =0{No} one{A} other{#}} {count, plural, one{Word} other{Words}}"