Changes in "scaposer.I18n.evaluatePluralForms"

31 views
Skip to first unread message

c0d3r85

unread,
Sep 20, 2016, 11:04:29 PM9/20/16
to scala-xgettext
I think, you should add ability to match plural forms, described in GNU gettext sources (gettext/gettext-tools/src/plural-table.c) for scaposer.I18n.evaluatePluralForms. The list of forms on http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms looks ill-formed.

Ngoc

unread,
Sep 21, 2016, 10:10:50 AM9/21/16
to scala-xgettext
As I understand, plural-table.c matches plural forms based on the specified languages. It seems a good idea.

But implementing like scaposer.I18n.evaluatePluralForms is also OK:
https://github.com/xitrum-framework/scaposer/blob/master/src/main/scala/scaposer/I18n.scala#L144

c0d3r85

unread,
Sep 21, 2016, 10:55:38 PM9/21/16
to scala-xgettext
Current implementation fails on autogenerated PO files with http://pootle.translatehouse.org/, cause plural forms definition contains braces, like in plural-table.c

среда, 21 сентября 2016 г., 21:10:50 UTC+7 пользователь Ngoc написал:

Ngoc

unread,
Sep 22, 2016, 6:36:26 PM9/22/16
to scala-xgettext
> cause plural forms definition contains braces, like in plural-table.c

Can you give some examples to clarify?
I don't see braces:
https://github.com/bennoleslie/gettext/blob/master/gettext-tools/src/plural-table.c

> Current implementation fails

What's your suggestion to fix it?
I think we should implement based on the language, because it's more reliable?

c0d3r85

unread,
Sep 22, 2016, 9:48:19 PM9/22/16
to scala-xgettext
Look at line #31 in plural-table.c. it contains "nplurals=2; plural=(n != 1);" . Braces around "n != 1"

пятница, 23 сентября 2016 г., 5:36:26 UTC+7 пользователь Ngoc написал:

c0d3r85

unread,
Sep 22, 2016, 10:03:02 PM9/22/16
to scala-xgettext
Maybe we should evaluate expression?
For example, parsing string "nplurals=2; plural=(n != 1);" gives us function "n => n != 1" with mapping true to 1 and false to 0 and get mod 2 (nplurals) we can get msg index. This method I used in JavaScript (just wrapping expression with function definition and the eval)

среда, 21 сентября 2016 г., 10:04:29 UTC+7 пользователь c0d3r85 написал:

c0d3r85

unread,
Sep 22, 2016, 10:21:27 PM9/22/16
to scala-xgettext

Ngoc

unread,
Sep 25, 2016, 6:20:36 PM9/25/16
to scala-xgettext
I don't think it's the best solution. It works like this:

* Use program msgfmt to compile .po files to .class files implementing java.util.ResourceBundle: https://www.gnu.org/software/gettext/manual/html_node/Java.html
* Inside the .class file, a special method pluralEval is generated
* When gnu.gettext.GettextResource#ngettext is called, it calls pluralEval: http://www.docjar.org/html/api/gnu/gettext/GettextResource.java.html

I could find the source code of program msgfmt, but I haven't found the code that generates pluralEval yet:
https://bitbucket.org/dkruchinin/illumos-nfslm/src/d9f4131126c2e18cbb61a40113aa33bceb66bc3a/usr/src/cmd/msgfmt/?at=default


> parsing string "nplurals=2; plural=(n != 1);"

I prefer this solution. I think we can easily create a parser in Scala. Can you write it and create a pull request?

Ngoc

unread,
Sep 25, 2016, 6:40:00 PM9/25/16
to scala-xgettext
> I think we can easily create a parser in Scala. Can you write it and create a pull request?

If writing the parser is not easy, we can simply list all common languages and their plural rules (if we miss a language, we can add it later):
https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms

This solution is simple and it should be the fastest at run time.

c0d3r85

unread,
Oct 15, 2016, 1:18:26 PM10/15/16
to scala-xgettext
I've implemented parser https://github.com/xitrum-framework/scaposer/pull/17
Don't test it for speed.

понедельник, 26 сентября 2016 г., 5:40:00 UTC+7 пользователь Ngoc написал:

Ngoc

unread,
Oct 15, 2016, 8:16:54 PM10/15/16
to scala-xgettext
Thanks.
I've merged your PR.
I'll release a new version soon.
Reply all
Reply to author
Forward
0 new messages