Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreProcessor.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
24  protected $config;
25 
29  protected $areaList;
30 
34  protected $translate;
35 
42  {
43  $this->config = $config;
44  $this->areaList = $areaList;
45  $this->translate = $translate;
46  }
47 
54  public function process(Chain $chain)
55  {
56  if ($this->config->isEmbeddedStrategy()) {
57  $context = $chain->getAsset()->getContext();
58 
60 
61  if ($context instanceof FallbackContext) {
62  $areaCode = $context->getAreaCode();
63  $this->translate->setLocale($context->getLocale());
64  }
65 
66  $area = $this->areaList->getArea($areaCode);
67  $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
68 
69  $chain->setContent($this->translate($chain->getContent()));
70  }
71  }
72 
79  public function translate($content)
80  {
81  foreach ($this->config->getPatterns() as $pattern) {
82  $content = preg_replace_callback($pattern, [$this, 'replaceCallback'], $content);
83  }
84  return $content;
85  }
86 
93  protected function replaceCallback($matches)
94  {
95  return '"' . __($matches[1]) . '"';
96  }
97 }
$pattern
Definition: website.php:22
__()
Definition: __.php:13
__construct(Config $config, AreaList $areaList, TranslateInterface $translate)