Bluz\Translator\Translator::translatePlural PHP Method

translatePlural() public static method

Example of usage plural form + sprintf equal to sprintf(ngettext('%d comment', '%d comments', 4), 4) Translator::translatePlural('%d comment', '%d comments', 4, 4) Example of usage plural form + sprintf equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic') Translator::translatePlural('%d comment to %s', '%d comments to %s', 4, 'Topic')
public static translatePlural ( string $singular, string $plural, integer $number, $text ) : string
$singular string
$plural string
$number integer
$text
return string
    public static function translatePlural($singular, $plural, $number, ...$text)
    {
        if (function_exists('ngettext')) {
            $message = ngettext($singular, $plural, $number);
        } else {
            $message = $singular;
        }
        if (func_num_args() > 3) {
            // first element is number
            array_unshift($text, $number);
            $message = vsprintf($message, $text);
        }
        return $message;
    }

Usage Example

Beispiel #1
0
 /**
  * Test Plural Translate
  */
 public function testPluralTranslateWithAdditionalParams()
 {
     $translator = new Translator();
     $translator->setDomain('messages');
     $translator->setLocale('uk_UA');
     $translator->setPath(PATH_APPLICATION . '/locale');
     if (function_exists('ngettext')) {
         $this->assertEquals('2 messages', $translator->translatePlural('%d message', '%d messages', 2, 2));
     } else {
         $this->assertEquals('2 message', $translator->translatePlural('%d message', '%d messages', 2, 2));
     }
 }
All Usage Examples Of Bluz\Translator\Translator::translatePlural