Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DataProvider.php #8217

Merged
merged 7 commits into from
Feb 11, 2017
Merged
Changes from 5 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
17 changes: 12 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,14 @@ 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 +141,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