[RFC|Merged] Plural forms

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
Qiaeru
Registered User
Posts: 32
Joined: Thu Jul 07, 2005 7:45 am
Location: Paris, France
Contact:

[RFC|Merged] Plural forms

Post by Qiaeru »

kenan3008, Bosnian language package maintainer, just point out that our system is failing in the plural forms area. I quote him:
kenan3008 wrote:I have one problem with plural forms. As you already know, situation with singular and plural forms in English is quite simple. One of something is singular and everything above that is plural. In Bosnian (like in most Slavic languages), we have a more complex situation. Here is an example:
Bosnian word for elephant is "slon".
English: 1 elephant, 2 elephants, 3 elephants etc. (stupid example :D)
Bosnian:
for numbers 0,5,6 and those ending with these numbers (like 25):
0 slonova, 5 slonova, 6 slonova

for numbers 2,3,4 and those ending with these numbers (like 22):
2 slona, 3 slona, 4 slona

for numbers 1,21,31,... :
1 slon, 21 slon, 31, slon

In software that uses PO/MO architecture this is solved by adding an equation for plural forms (for example, WordPress uses that system). For Bosnian, this equation is:
nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)
where n is the number of something. Complete list of languages and their plural forms is available here: http://translate.sourceforge.net/wiki/l10n/pluralforms
After adding this equation, I get three rows for every string that has plural form and I am able to type in everything correctly. Depending on the number that is displayed in the string, one of these three translations is pulled and displayed to the user. Is it possible to implement something like that into phpBB's translation?
It would be preferable to integrate this system of equations, avoiding incorrect translations. I do not know if it is easy to implement because we're not using PO/MO and it looks complex, or if this system is the best, but the actual string system is not sufficient with some languages, like Bosnian:

Code: Select all

    // Nullar/Singular/Plural language entry. The key numbers define the number range in which a certain grammatical expression is valid.
    'NUM_POSTS_IN_QUEUE'        => array(
        0            => 'No posts in queue',        // 0
        1            => '1 post in queue',        // 1
        2            => '%d posts in queue',        // 2+
    ), 
What do you think? Your feedbacks would be appreciated ;) .

Ticket
Pull request

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: Plural forms

Post by Oleg »

For anyone seriously interested in tackling this project I suggest looking at gettext (which is what kenan3008 referred to) and in particular plural forms.

Practically useful starting points for gettext-compatible php implementations: https://github.com/dsp/PHP-Gettext and https://github.com/voda/php-gettext. Note that they may not actually support all of gettext's features (such as plural forms). I have not looked into them closely.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: Plural forms

Post by Oleg »

I came across Symfony Translation component and it appears to also do things the Right Way(TM).

https://github.com/symfony/symfony/tree ... ranslation

TheIlluminative
Registered User
Posts: 3
Joined: Sat Sep 13, 2003 11:54 pm
Location: <div>Here</div>
Contact:

Re: Plural forms

Post by TheIlluminative »

Yes, same thing happens in Arabic also.
To quote the same example you used, in singular word "1 elephant" we would say: "فيل"
For 2 numbers, we say: "فيلين"
We begin to use numbers beginning from 3, and again from numbers 3 to 10 we say: "3 أفيال" or "7 أفيال"
For more than 10 numbers we say: "11 فيل" or "243 فيل"

I hope you get the idea, so it would be actually really interesting and useful to add that equation for plural nouns.

Edit: The numbers actually should appear to the right of the word, but since this site uses "ltr" then it's displayed like that.

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Plural forms

Post by nickvergessen »

Oleg wrote:I came across Symfony Translation component and it appears to also do things the Right Way(TM).

https://github.com/symfony/symfony/tree ... ranslation
Well seems like a huge list of language iso-s ;)

I'd go the way of https://developer.mozilla.org/en/Locali ... ural_Rules
So we basically implement the rules (mostly the same as in symfony) but use a int key which rule to take.
Language package authors than simply specify the rule they want to use.

This has the advantage that we do not need to list all packages in the source or need to update it when a new lang package got submitted.

But either is fine for me.

Ticket: http://tracker.phpbb.com/browse/PHPBB3-10345
Member of the Development-TeamNo Support via PM

TheIlluminative
Registered User
Posts: 3
Joined: Sat Sep 13, 2003 11:54 pm
Location: <div>Here</div>
Contact:

Re: Plural forms

Post by TheIlluminative »

nickvergessen wrote:Well seems like a huge list of language iso-s ;)

I'd go the way of https://developer.mozilla.org/en/Locali ... ural_Rules
So we basically implement the rules (mostly the same as in symfony) but use a int key which rule to take.
Language package authors than simply specify the rule they want to use.

This has the advantage that we do not need to list all packages in the source or need to update it when a new lang package got submitted.

But either is fine for me.

Ticket: http://tracker.phpbb.com/browse/PHPBB3-10345
This seems like a very good approach Nick, way to go ;)

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Plural forms

Post by nickvergessen »

I posted a page in the wiki:
http://wiki.phpbb.com/Plural_Rules

Feel free to tell me if something is missing. :geek:

Pull-Request: https://github.com/phpbb/phpbb3/pull/363
Member of the Development-TeamNo Support via PM

User avatar
Qiaeru
Registered User
Posts: 32
Joined: Thu Jul 07, 2005 7:45 am
Location: Paris, France
Contact:

Re: Plural forms

Post by Qiaeru »

Great job, thanks! By the way, translators have been informed about this topic :) .

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: Plural forms

Post by Oleg »

(14:44:11) A_Jelly_Donut: 10345 is scheduled to be merged into develop-olympus? it would be pretty useless in 3.0 :/
(14:45:58) nn-: why is that?
(14:47:27) A_Jelly_Donut: user::lang is not used
(14:48:17) nn-: are you implying the patch is incomplete?
(14:48:21) nn-: i don't understand what you're saying
(14:50:09) A_Jelly_Donut: moment, I'll explain
(14:52:41) A_Jelly_Donut: user->lang(), the method where the implementation is added, is only called 12 times in all of 3.0.x
(14:53:09) A_Jelly_Donut: most of the pluralizations are done with ternaries ... e.g.
(14:54:01) A_Jelly_Donut: ($count == 1) ? $user->lang['L_FOO_1'] : sprintf($user->lang['L_FOO'], $count);
(14:56:41) nn-: that looks fixable
(14:57:01) nn-: if there is a consistent naming scheme for L_FOO_1 we can incorporate it into lang as a fallback
(14:58:27) nn-: the worst case would be having to rewrite all those operators and translations
(14:59:00) nn-: translators might prefer doing that to keeping old behavior
(15:04:34) A_Jelly_Donut: I'd say keeping full bc with current translations would be tough

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Plural forms

Post by nickvergessen »

Well, there is another problem with the lang() function.
we kind of abuse it on the format_date function to view the "less than a minute ago" and such strings:

Code: Select all

return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
So, we either need to add a parameter to lang() which says use plural-rules (bool) or we need to use another function name, maybe $user->plural() or lang_plural() or something.

This also means it will not really be backwards compatible and all places using plurals need to be edited in one or the other way.
Or we break the datetime thing and maybe some mods and add a function for the "abuse" case where plural-rules shall not be used.
Member of the Development-TeamNo Support via PM

Post Reply