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

About PluralTranslate()

OniaOnia New
edited February 2013 in Localization

Could someone tell me how to localize the following strings?

\applications\vanilla\views\discussions\helper_functions.php

 printf(PluralTranslate($Discussion->CountComments, 
               '%s comment html', '%s comments html', '%s comment', '%s comments'),
               BigPlural($Discussion->CountComments, '%s comment'));

my language pack:

$Definition['%s comment'] = '%s XXXX';
$Definition['%s comments'] = '%s XXXX';

It didn't work.

Tagged:

Best Answer

  • KasperKasper Vanilla Staff
    Answer ✓

    Here's the function:

    function PluralTranslate($Number, $Singular, $Plural, $SingularDefault = FALSE, $PluralDefault = FALSE) {
        if ($Number == 1)
            return T($Singular, $SingularDefault);
        else
            return T($Plural, $PluralDefault);
    }
    

    Meaning that your locale definitions should look like this:

    $Definition['%s comment html'] = '%s XXXX';
    $Definition['%s comments html'] = '%s XXXX';
    

    Why is that? Because the $Singular and $Plural variables are the ones being used as identifiers in the PluralTranslate function (e.g. T($Singular, $SingularDefault).

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

Answers

  • KasperKasper Vanilla Staff
    Answer ✓

    Here's the function:

    function PluralTranslate($Number, $Singular, $Plural, $SingularDefault = FALSE, $PluralDefault = FALSE) {
        if ($Number == 1)
            return T($Singular, $SingularDefault);
        else
            return T($Plural, $PluralDefault);
    }
    

    Meaning that your locale definitions should look like this:

    $Definition['%s comment html'] = '%s XXXX';
    $Definition['%s comments html'] = '%s XXXX';
    

    Why is that? Because the $Singular and $Plural variables are the ones being used as identifiers in the PluralTranslate function (e.g. T($Singular, $SingularDefault).

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • @kasperisager Solved! Thanks for your help.

Sign In or Register to comment.