Fork me on GitHub
Current releases are 2.1.3 (9 Sept 2014) and 2.0.18.13 (5 Aug 2014)

Ready for 2.1? Find out if your favorite plugins are compatible. The 2.0 branch will no longer receive updates after Dec 2014.

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

Sign In or Register to comment.