本文整理汇总了PHP中Zend\I18n\Translator\Translator::translatePlural方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::translatePlural方法的具体用法?PHP Translator::translatePlural怎么用?PHP Translator::translatePlural使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\I18n\Translator\Translator
的用法示例。
在下文中一共展示了Translator::translatePlural方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Translate a plural message.
*
* @param string $singular
* @param string $plural
* @param integer $number
* @param string $textDomain
* @param string $locale
* @return string
* @throws Exception\RuntimeException
*/
public function __invoke($singular, $plural, $number, $textDomain = 'default', $locale = null)
{
if ($this->translator === null) {
throw new Exception\RuntimeException('Translator has not been set');
}
return $this->translator->translatePlural($singular, $plural, $number, $textDomain, $locale);
}
示例2: testTranslatePlural
public function testTranslatePlural()
{
$singular = 'foo bar';
$plural = 'bar foo';
$number = 1;
$this->assertEquals($this->translator->translatePlural($singular, $plural, $number), $this->extension->translatePlural($singular, $plural, $number));
}
示例3: translatePlural
public function translatePlural($singular, $plural, $number, $textDomain, $locale)
{
if ($this->translator === null) {
$this->translator = $this->getApplicationServiceLocator()->get('translator');
}
return $this->translator->translatePlural($singular, $plural, $number, $textDomain, $locale);
}
示例4: testTranslatePlurals
public function testTranslatePlurals()
{
$this->translator->setLocale('en_EN');
$this->translator->addTranslationFile('phparray', $this->testFilesDir . '/translation_en.php', 'default', 'en_EN');
$pl0 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 1);
$pl1 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 2);
$pl2 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 10);
$this->assertEquals('Message 5 (en) Plural 0', $pl0);
$this->assertEquals('Message 5 (en) Plural 1', $pl1);
$this->assertEquals('Message 5 (en) Plural 2', $pl2);
}
示例5: translatePlural
/**
* {@inheritDoc}
*/
public function translatePlural($singular, $plural, $number, $textDomain = null, $locale = null)
{
if (!$textDomain) {
$textDomain = $this->getTextDomain();
}
return parent::translatePlural($singular, $plural, $number, $textDomain, $locale);
}
示例6: translatePlural
/**
* Translate a plural message.
*
* @param string $singular
* @param string $plural
* @param int $number
* @param string $textDomain
* @param string|null $locale
* @return string
* @throws Exception\OutOfBoundsException
*/
public function translatePlural($singular, $plural, $number, $textDomain = 'default', $locale = null)
{
$locale = (string) $locale ?: $this->getLocale();
$textDomain = strstr($singular, '.', true) ?: strstr($plural, '.', true) ?: $textDomain;
$translation = $this->getTranslatedMessage($singular, $locale, $textDomain);
if (is_array($translation) || $translation instanceof ArrayAccess) {
if (isset($this->messages[$textDomain][$locale])) {
return parent::translatePlural($singular, $plural, $number, $textDomain, $locale);
}
$index = $this->myMessages[$textDomain][$locale]->getPluralRule()->evaluate($number);
if (!isset($translation[$index])) {
throw new Exception\OutOfBoundsException(sprintf('Provided index %d does not exist in plural array', $index));
}
return $translation[$index];
}
return parent::translate(1 == $number ? $singular : $plural, $textDomain, $locale);
}