本文整理汇总了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);
}
示例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'));
}
示例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'));
}
示例4: addErrorMessage
public function addErrorMessage($message)
{
if ($this->translator) {
$namespace = explode('\\', get_class($this))[0];
$message = $this->translator->translate($message, $namespace);
}
$this->errorMessages[] = $message;
}
示例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;
}
示例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'));
}
示例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);
}
示例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;
}
示例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;
}
}
}
}
示例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);
}
示例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);
}
示例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']);
}
示例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);
}
示例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;
}
示例15: __
protected function __($text, $parameters = array())
{
return vsprintf($this->translator->translate($text), $parameters);
}