Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Contextual.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
20  protected $_context;
21 
29  public function __construct(I18n\FilesCollector $filesCollector, I18n\Factory $factory, I18n\Context $context)
30  {
31  $this->_context = $context;
32 
33  parent::__construct($filesCollector, $factory);
34  }
35 
42  protected function _parseByTypeOptions($options)
43  {
44  foreach ($this->_getFiles($options) as $file) {
45  $adapter = $this->_adapters[$options['type']];
46  $adapter->parse($file);
47 
48  list($contextType, $contextValue) = $this->_context->getContextByPath($file);
49 
50  foreach ($adapter->getPhrases() as $phraseData) {
51  $this->_addPhrase($phraseData, $contextType, $contextValue);
52  }
53  }
54  }
55 
64  protected function _addPhrase($phraseData, $contextType, $contextValue)
65  {
66  $phraseKey = $contextType . $contextValue. stripslashes($phraseData['phrase']);
67 
68  if (isset($this->_phrases[$phraseKey])) {
70  $phrase = $this->_phrases[$phraseKey];
71  $phrase->addContextValue($contextValue);
72  } else {
73  $this->_phrases[$phraseKey] = $this->_factory->createPhrase(
74  [
75  'phrase' => $phraseData['phrase'],
76  'translation' => $phraseData['phrase'],
77  'context_type' => $contextType,
78  'context_value' => [$contextValue],
79  'quote' => $phraseData['quote'],
80  ]
81  );
82  }
83  }
84 }
$adapter
Definition: webapi_user.php:16
__construct(I18n\FilesCollector $filesCollector, I18n\Factory $factory, I18n\Context $context)
Definition: Contextual.php:29