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.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

Plural forms problems

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... :)


  • SS ✭✭
    edited June 2010

    Example plural translate for your language.
    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();

    $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:

Sign In or Register to comment.