当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator::translatePlural方法代码示例

本文整理汇总了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);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:18,代码来源:TranslatePlural.php

示例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));
 }
开发者ID:kukoman,项目名称:website-expressive,代码行数:7,代码来源:TranslatorExtensionTest.php

示例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);
 }
开发者ID:evolic,项目名称:loculus,代码行数:7,代码来源:HttpControllerTestCase.php

示例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);
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:11,代码来源:TranslatorTest.php

示例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);
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:10,代码来源:Translator.php

示例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);
 }
开发者ID:gridguyz,项目名称:zork,代码行数:28,代码来源:Translator.php


注:本文中的Zend\I18n\Translator\Translator::translatePlural方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。