diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index c6aa79f1438e7..c300663bfbc19 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -6,6 +6,8 @@ namespace Magento\Translation\Model\Js; +use Magento\Framework\LocalizedException; + /** * DataProvider for js translation */ @@ -103,9 +105,15 @@ public function getData($themePath) $read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE); $content = $read->readAll(); foreach ($this->getPhrases($content) as $phrase) { - $translatedPhrase = $this->translate->render([$phrase], []); - if ($phrase != $translatedPhrase) { - $dictionary[$phrase] = $translatedPhrase; + try { + $translatedPhrase = $this->translate->render([$phrase], []); + if ($phrase != $translatedPhrase) { + $dictionary[$phrase] = $translatedPhrase; + } + } catch (\Exception $e) { + throw new LocalizedException( + sprintf(__('Error while translating phrase "%s" in file %s.'), $phrase, $filePath[0]) + ); } } } @@ -134,8 +142,8 @@ protected function getPhrases($content) } } if (false === $result) { - throw new \Exception( - sprintf('Error while generating js translation dictionary: "%s"', error_get_last()) + throw new LocalizedException( + sprintf(__('Error while generating js translation dictionary: "%s"'), error_get_last()) ); } }