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
Example #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));
     }
 }
Example #2
0
 /**
  * Translate plural form
  *
  * Example of usage
  *     // plural form + sprintf
  *     // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4)
  *     _n('%d comment', '%d comments', 4, 4)
  *
  *     // plural form + sprintf
  *     // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic')
  *     _n('%d comment to %s', '%d comments to %s', 4, 'Topic')
  *
  * @param  string   $singular
  * @param  string   $plural
  * @param  integer      $number
  * @param  string[] $text      [optional]
  * @return string
  */
 function _n($singular, $plural, $number, ...$text)
 {
     return Translator::translatePlural($singular, $plural, $number, ...$text);
 }