etnt / gettext

Erlang internationalization library.
http://www.redhoterlang.com/
MIT License
70 stars 45 forks source link

Plural / ngettext support #18

Open seriyps opened 10 years ago

seriyps commented 10 years ago

Some support for ngettext(Singular, Plural, Count) + evaluator for pluralization rules from Plural-Forms .po header may be good thing.

Plural-Forms: nplurals=3; \
              plural=n%10==1 && n%100!=11 ? 0 : \
                     n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;

http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html

etnt commented 10 years ago

Hm...note that this gettext lib doesn't have anything in common with GNU gettext (apart from using the PO file format).

richcarl commented 10 years ago

Still, I agree that such functions would be useful.

seriyps commented 10 years ago

@richcarl I have gettext rule evaluator implemented there https://github.com/seriyps/gettexter/tree/master/src (see gettexter_plural.erl, gettexter_plural_parser.yrl, gettexter_plural_scanner.xrl). Rule may be evaluated by erl_eval or compiled to .beam.