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


PHP Translator::translate方法代码示例

本文整理汇总了PHP中Zend\I18n\Translator\Translator::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::translate方法的具体用法?PHP Translator::translate怎么用?PHP Translator::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\I18n\Translator\Translator的用法示例。


在下文中一共展示了Translator::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: translate

 public function translate($text)
 {
     if ($this->translator === null) {
         $this->translator = $this->getApplicationServiceLocator()->get('translator');
     }
     return $this->translator->translate($text);
 }
开发者ID:evolic,项目名称:loculus,代码行数:7,代码来源:HttpControllerTestCase.php

示例2: testTranslatorAddsPattern

 public function testTranslatorAddsPattern()
 {
     $translator = new Translator();
     $translator->addTranslationPattern('phparray', $this->testFilesDir . '/testarray', 'translation-%s.php');
     $this->assertEquals('Message 1 (en)', $translator->translate('Message 1', 'default', 'en_US'));
     $this->assertEquals('Nachricht 1', $translator->translate('Message 1', 'default', 'de_DE'));
 }
开发者ID:navassouza,项目名称:zf2,代码行数:7,代码来源:PhpArrayTest.php

示例3: testTranslate

 public function testTranslate()
 {
     $loader = new TestLoader();
     $loader->textDomain = new TextDomain(array('foo' => 'bar'));
     $this->translator->getPluginManager()->setService('test', $loader);
     $this->translator->addTranslationFile('test', null);
     $this->assertEquals('bar', $this->translator->translate('foo'));
 }
开发者ID:navassouza,项目名称:zf2,代码行数:8,代码来源:TranslatorTest.php

示例4: addErrorMessage

 public function addErrorMessage($message)
 {
     if ($this->translator) {
         $namespace = explode('\\', get_class($this))[0];
         $message = $this->translator->translate($message, $namespace);
     }
     $this->errorMessages[] = $message;
 }
开发者ID:hoangpt,项目名称:nextcms,代码行数:8,代码来源:Entity.php

示例5: getElementById

 /**
  * Get One Element By Id
  * @param $id
  * @return string
  */
 public function getElementById($id)
 {
     if (!isset($this->list[$id])) {
         return null;
     }
     $element = $this->list[$id];
     $translatedElement = $this->translator->translate($element, 'GdproList');
     return $translatedElement;
 }
开发者ID:gdpro,项目名称:gdpro-list,代码行数:14,代码来源:AbstractList.php

示例6: testTranslateWithCache

 public function testTranslateWithCache()
 {
     $cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
     $this->translator->setCache($cache);
     $loader = new TestLoader();
     $loader->textDomain = new TextDomain(array('foo' => 'bar'));
     $this->translator->getPluginManager()->setService('test', $loader);
     $this->translator->addTranslationFile('test', null);
     $this->assertEquals('bar', $this->translator->translate('foo'));
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:10,代码来源:TranslatorTest.php

示例7: __invoke

 /**
  * @param $str
  * @param pt_BR $locale
  * @return string
  */
 public function __invoke($str, $locale = 'pt_BR', $typeTranslate = 'PhpArray', $pathFileTranslate = null)
 {
     $translator = new Translator();
     if (!empty($pathFileTranslate)) {
         $translator->addTranslationFile($typeTranslate, $pathFileTranslate, 'default', $locale);
     }
     return $translator->translate($str, $locale);
 }
开发者ID:cityware,项目名称:city-mvc,代码行数:13,代码来源:TranslatePlugin.php

示例8: translateRoutes

 /**
  * Translate the route texts
  *
  * @param array $routes
  *
  * @return array
  */
 protected function translateRoutes(array $routes = array())
 {
     foreach ($routes as $routeKey => $routeParams) {
         if (isset($routeParams['description'])) {
             $routes[$routeKey]['description'] = $this->translator->translate($routeParams['description']);
         }
         if (isset($routeParams['short_description'])) {
             $routes[$routeKey]['short_description'] = $this->translator->translate($routeParams['short_description']);
         }
         if (isset($routeParams['options_descriptions'])) {
             foreach ($routeParams['options_descriptions'] as $optionKey => $optionText) {
                 $routes[$routeKey]['options_descriptions'][$optionKey] = $this->translator->translate($optionText);
             }
         }
     }
     return $routes;
 }
开发者ID:samsonasik,项目名称:zf2rapid,代码行数:24,代码来源:Application.php

示例9: setValidatorMessages

 /**
  * Sets custom messages to filter input validators.
  * If provided $validators[], it will be filled with validator instances to be attached further on to a filter input,
  * otherwise the validator messages of the particular filter input provided will be amended accordingly.
  *
  * @param InputInterface $input
  * @param null|callback $inputLabel
  * @param null|array $validators
  */
 public function setValidatorMessages(InputInterface $input, $inputLabel = null, &$validators = null)
 {
     if (!is_null($validators) && !is_array($validators)) {
         throw new \InvalidArgumentException();
     }
     $inputLabel = is_callable($inputLabel) ? $inputLabel() : '';
     foreach ($input->getValidatorChain()->getValidators() as $validator) {
         //set message to validator StringLength
         if (isset($validator['instance']) && $validator['instance'] instanceof Validator\StringLength) {
             $validatorInstance = is_null($validators) ? $validator['instance'] : clone $validator['instance'];
             $validatorInstance->setMessage(sprintf($this->translator->translate('The input %s is more than %%max%% characters long'), $this->translator->translate($inputLabel)), Validator\StringLength::TOO_LONG);
             if (is_array($validators)) {
                 $validators[] = $validatorInstance;
             }
         }
     }
 }
开发者ID:veniva,项目名称:zcms,代码行数:26,代码来源:ValidatorMessages.php

示例10: translate

 public function translate($message, $textDomain = 'default', $locale = null)
 {
     if ($textDomain != 'default') {
         $this->setTextDomain($textDomain);
     }
     if ($locale != null) {
         $this->setLocale($locale);
     }
     return parent::translate($message, $this->textDomain, $this->locale);
 }
开发者ID:argentinaluiz,项目名称:js_zf2_library,代码行数:10,代码来源:Translator.php

示例11: addMail

 /**
  * @param string $queue_name
  * @param string $to
  * @param string $subject
  * @param string $body
  * @param null $from
  * @param true $html
  */
 public function addMail($queue_name, $to, $subject, $body, $from = null, $html = false)
 {
     $message = new \Zend\Mail\Message();
     $message->setTo($to);
     $message->setSubject($this->translate ? $this->translate->translate($subject) : $subject);
     if ($html) {
         $bodyPart = new \Zend\Mime\Message();
         $bodyMessage = new \Zend\Mime\Part($body);
         $bodyMessage->type = 'text/html';
         $bodyPart->setParts(array($bodyMessage));
         $message->setBody($bodyPart);
     } else {
         $message->setBody($body);
     }
     $message->setEncoding("UTF-8");
     if ($from) {
         $message->setFrom($from);
     } else {
         $message->setFrom($this->config['default_from']);
     }
     $this->table->add($queue_name, $message);
 }
开发者ID:cobyl,项目名称:ppmodulemailer,代码行数:30,代码来源:Service.php

示例12: testTranslationsAreStoredInCache

 public function testTranslationsAreStoredInCache()
 {
     $cache = \Zend\Cache\StorageFactory::factory(array('adapter' => 'memory'));
     $this->translator->setCache($cache);
     $loader = new TestLoader();
     $loader->textDomain = new TextDomain(array('foo' => 'bar'));
     $this->translator->getPluginManager()->setService('test', $loader);
     $this->translator->addTranslationFile('test', null);
     $this->assertEquals('bar', $this->translator->translate('foo'));
     $item = $cache->getItem('Zend_I18n_Translator_Messages_' . md5('default' . 'en_EN'));
     $this->assertInstanceOf('Zend\\I18n\\Translator\\TextDomain', $item);
     $this->assertEquals('bar', $item['foo']);
 }
开发者ID:nieldm,项目名称:zf2,代码行数:13,代码来源:TranslatorTest.php

示例13: testListenerOnNoMessagesLoadedEventCanReturnTextDomainObject

 public function testListenerOnNoMessagesLoadedEventCanReturnTextDomainObject()
 {
     $trigger = null;
     $doNotTrigger = null;
     $textDomain = new TextDomain(array('foo' => 'BOOYAH'));
     $this->translator->enableEventManager();
     $events = $this->translator->getEventManager();
     $events->attach(Translator::EVENT_NO_MESSAGES_LOADED, function (EventInterface $event) use(&$trigger) {
         $trigger = true;
     });
     $events->attach(Translator::EVENT_NO_MESSAGES_LOADED, function (EventInterface $event) use($textDomain) {
         return $textDomain;
     });
     $events->attach(Translator::EVENT_NO_MESSAGES_LOADED, function (EventInterface $event) use(&$doNotTrigger) {
         $doNotTrigger = true;
     });
     $result = $this->translator->translate('foo', 'bar', 'baz');
     $this->assertTrue($trigger);
     $this->assertNull($doNotTrigger);
     $this->assertEquals('BOOYAH', $result);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:21,代码来源:TranslatorTest.php

示例14: translate

 /**
  * Translate a string if a translator is provided.
  *
  * @param string $msg Message to translate
  *
  * @return string
  */
 public function translate($msg)
 {
     return null !== $this->translator ? $this->translator->translate($msg) : $msg;
 }
开发者ID:no-reply,项目名称:cbpl-vufind,代码行数:11,代码来源:Mailer.php

示例15: __

 protected function __($text, $parameters = array())
 {
     return vsprintf($this->translator->translate($text), $parameters);
 }
开发者ID:kminh,项目名称:phpDocumentor2,代码行数:4,代码来源:ParseCommand.php


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