Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app/code/Magento/Translation/Model/Js/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Translation\Model\Js;

use Magento\Framework\LocalizedException;

/**
* DataProvider for js translation
*/
Expand Down Expand Up @@ -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])
);
}
}
}
Expand Down Expand Up @@ -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())
);
}
}
Expand Down