Fork me on GitHub

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

In this Discussion

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Current release is 2.1.6 (21 Nov 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

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.