當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。