Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitialTranslationSource.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Translation\Model\ResourceModel\TranslateFactory;
14 
19 {
23  private $translateFactory;
24 
28  private $storeManager;
29 
33  private $data;
34 
38  private $deploymentConfig;
39 
45  public function __construct(
46  TranslateFactory $translateFactory,
47  StoreManager $storeManager,
48  DeploymentConfig $deploymentConfig
49  ) {
50  $this->translateFactory = $translateFactory;
51  $this->storeManager = $storeManager;
52  $this->deploymentConfig = $deploymentConfig;
53  }
54 
61  public function get($path = '')
62  {
63  if (!$this->deploymentConfig->isDbAvailable()) {
64  return [];
65  }
66 
67  if (!$this->data) {
69  $translate = $this->translateFactory->create();
70  $select = $translate->getConnection()->select()
71  ->from($translate->getMainTable(), ['string', 'translate', 'store_id', 'locale'])
72  ->order('store_id');
73  $translations = [];
74  foreach ($translate->getConnection()->fetchAll($select) as $item) {
75  $store = $this->storeManager->getStore($item['store_id']);
76  $translations[$item['locale']][$store->getCode()][$item['string']] = $item['translate'];
77  }
78  $this->data = new DataObject($translations);
79  }
80  return $this->data->getData($path) ?: [];
81  }
82 }
$storeManager
$deploymentConfig
__construct(TranslateFactory $translateFactory, StoreManager $storeManager, DeploymentConfig $deploymentConfig)