config = $config; $this->dataProvider = $dataProvider; $this->areaList = $areaList; $this->translate = $translate; $this->viewDesign = $viewDesign ?? ObjectManager::getInstance()->get(DesignInterface::class); } /** * Transform content and/or content type for the specified preprocessing chain object * * @param Chain $chain * @return void */ public function process(Chain $chain) { if ($this->isDictionaryPath($chain->getTargetAssetPath())) { $context = $chain->getAsset()->getContext(); $themePath = '*/*'; $areaCode = FrontNameResolver::AREA_CODE; if ($context instanceof FallbackContext) { $themePath = $context->getThemePath(); $areaCode = $context->getAreaCode(); $this->viewDesign->setDesignTheme($themePath, $areaCode); } if ($areaCode !== FrontNameResolver::AREA_CODE) { $area = $this->areaList->getArea($areaCode); $area->load(Area::PART_TRANSLATE); } $this->translate->setLocale($context->getLocale())->loadData($areaCode, true); $chain->setContent(json_encode($this->dataProvider->getData($themePath))); $chain->setContentType('json'); } } /** * Is provided path the path to translation dictionary * * @param string $path * @return bool */ protected function isDictionaryPath($path) { return (strpos($path, $this->config->getDictionaryFileName()) !== false); } }