bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gettext] Plural rule definitions


From: Daiki Ueno
Subject: Re: [bug-gettext] Plural rule definitions
Date: Fri, 22 May 2015 16:55:46 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Michele Locati <address@hidden> writes:

>     de nplurals=2; plural=(n != 1);
[...]
>
> For the above locales, the tool of mine strips out the extra
> parenthesis.

Yes, my intent was to make the output resemble the current style of
plural-table.c as much as possible, to make the initial diff smaller.

I also tried to omit spaces around operators if a relation is not
top-level and to insert minimal number of parentheses when relations are
connected with '&&' and '||', as you noticed.

BTW, for samples, I plan to add a separate array, say
plural_sample_table to avoid confusion.

> Another difference here is the use of parenthesis. As I described at
> https://github.com/mlocati/cldr-to-gettext-plural-rules#parenthesis-in-ternary-operators

[...]

> Empty plural rules for Brazilian Portuguese?

Oops, my local copy of plurals.xml was from CLDR 25 :-)

>     ru nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 &&
>     n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 &&
>     n%10<=9) || (n%100>=11 && n%100<=14) ? 2 : 3);
>
> The plural rules are 3 for Russian, not 4. I had the same strange
> result as you in an old version of my tool. It's quite a complicated
> case, but here's what the above function means: - if n ends with 1 but
> not with 11: case 0 (named to "one" in CLDR for ru) - if n ends with
> 2, 3 or 4 (but not with 12, 13 or 14): case 1 (named to "few" in CLDR
> for ru) - if n ends with 0, 5, 6, 7, 8, 9, 11, 12, 13, 14: case 2
> (named to "many" in CLDR for ru) As you can see, the case 3 (named to
> "other" in CLDR for ru) never occur.  So, we should strip the case 3.
> I discovered it because in the CLDR data there is no example for the
> "other" case (ie no "@integer" in the pluralRule node of plurals.xml).

Interesting, thanks for the explanation.

> Here's the approach that I used (quite pragmatical, I know):
> https://github.com/mlocati/cldr-to-gettext-plural-rules/blob/8222bf07d11871693292dd97d8d884b08b12c043/src/Language.php#L174

I hit on an algorithm:

- From all rules, find the largest modulo M (here 100)

- Prepare a bit vector with M elements and initialize it with zeros

- Loop over the rules
  - For each value in the range [1, M], apply a rule, and flip the
    corresponding bit if it evaluates true
  - Stop if all bits are set

Maybe we can also omit rules which don't change the vector, but it seems
to work with the Russian case so far:
http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-tools/src/cldr-plural-exp.c?h=wip/ueno/cldr-plural#n546

Regards,
-- 
Daiki Ueno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]