HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Plural forms problems

TiGRTiGR
edited June 2010 in Localization
Plural function receives 3 arguments: number, single and plural form. There are 2 problems:

1. Some languages have more than 2 forms.
2. Some phrases with numerals are the same in english ("1 new" and "10 new").
2.1. And because of that Vanilla authors did not pluralize such phrases :) (quick tip: search for "%s new", there are three occurrences, and all of them are not plural and some of them even not translatable [no T() call]).

There are solutions for all of these problems, but maybe something could be done with Plural function itself to make it work better.

Currently possible solutions:

1. For third plural form use some kind of suffix (e.g., "_many")and add it to original string.
2. Make Plural function check if single form is the same as plural, and if they are, add another suffix.
2.1. Umm... :)
Tagged:

Comments

  • SS ✭✭
    edited June 2010
    http://vanillaforums.org/discussion/comment/100410/#Comment_100410
    http://translate.sourceforge.net/wiki/l10n/pluralforms

    Example plural translate for your language.
    /locale/../definitions.php
    if(!function_exists('Plural')){
    function Plural($N, $Singular, $Plural) {
    $Form = PluralForm($N, '', '2', '5');
    return ($Form == '') ? Gdn::Translate($Singular, $Singular) : Gdn::Translate($Form.$Singular, $Plural);
    }
    }

    function PluralForm($Number, $F1, $F2, $F5){
    $N = $Number % 100;
    $Number = $Number % 10;
    if($Number == 1 && $N != 11) return $F1;
    if($Number > 1 && $Number < 5 && ($N < 10 || $N > 19)) return $F2;
    return $F5;
    }

    // unit testing:
    $Definition['%s comment'] = '%s comment';
    $Definition['2%s comment'] = '%s commenta';
    $Definition['5%s comment'] = '%s commentov';

    $Locale = Gdn::Locale();
    $Locale->SetTranslation($Definition);

    $TestNum = array(1,2,3,5,11,17,20,21,22,102,113, 133);
    foreach($TestNum as $N){
    echo sprintf(Plural($N, '%s comment', '%s comments'), $N) . "\n";
    }
    // output:
    1 comment
    2 commenta
    3 commenta
    5 commentov
    11 commentov
    17 commentov
    20 commentov
    21 comment
    22 commenta
    102 commenta
    113 commentov
    133 commenta

  • AlmazAlmaz
    edited July 2015

    Dear S,
    Please, tell me how can I resolve the same issue for Russian language?
    You can see the differences here: localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html

Sign In or Register to comment.