Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Translate.php
Go to the documentation of this file.
1 <?php
9 
12 use Psr\Log\LoggerInterface;
13 
14 class Translate implements RendererInterface
15 {
19  protected $translator;
20 
24  protected $logger;
25 
32  public function __construct(
34  LoggerInterface $logger
35  ) {
36  $this->translator = $translator;
37  $this->logger = $logger;
38  }
39 
49  public function render(array $source, array $arguments)
50  {
51  $text = end($source);
52  /* If phrase contains escaped quotes then use translation for phrase with non-escaped quote */
53  $text = str_replace('\"', '"', $text);
54  $text = str_replace("\\'", "'", $text);
55 
56  try {
57  $data = $this->translator->getData();
58  } catch (\Exception $e) {
59  $this->logger->critical($e->getMessage());
60  throw $e;
61  }
62 
63  return array_key_exists($text, $data) ? $data[$text] : end($source);
64  }
65 }
$source
Definition: source.php:23
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
render(array $source, array $arguments)
Definition: Translate.php:49
__construct(TranslateInterface $translator, LoggerInterface $logger)
Definition: Translate.php:32