Skip to content

Commit 8e867d5

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'origin/MAGETWO-64519-PR-8217' into develop-prs
2 parents 48d5a00 + c664d65 commit 8e867d5

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
namespace Magento\Translation\Model\Js;
88

9+
use Magento\Framework\Exception\LocalizedException;
10+
911
/**
1012
* DataProvider for js translation
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1115
*/
1216
class DataProvider implements DataProviderInterface
1317
{
@@ -103,9 +107,15 @@ public function getData($themePath)
103107
$read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE);
104108
$content = $read->readAll();
105109
foreach ($this->getPhrases($content) as $phrase) {
106-
$translatedPhrase = $this->translate->render([$phrase], []);
107-
if ($phrase != $translatedPhrase) {
108-
$dictionary[$phrase] = $translatedPhrase;
110+
try {
111+
$translatedPhrase = $this->translate->render([$phrase], []);
112+
if ($phrase != $translatedPhrase) {
113+
$dictionary[$phrase] = $translatedPhrase;
114+
}
115+
} catch (\Exception $e) {
116+
throw new LocalizedException(
117+
sprintf(__('Error while translating phrase "%s" in file %s.'), $phrase, $filePath[0])
118+
);
109119
}
110120
}
111121
}
@@ -118,7 +128,7 @@ public function getData($themePath)
118128
*
119129
* @param string $content
120130
* @return string[]
121-
* @throws \Exception
131+
* @throws \Magento\Framework\Exception\LocalizedException
122132
*/
123133
protected function getPhrases($content)
124134
{
@@ -134,8 +144,8 @@ protected function getPhrases($content)
134144
}
135145
}
136146
if (false === $result) {
137-
throw new \Exception(
138-
sprintf('Error while generating js translation dictionary: "%s"', error_get_last())
147+
throw new LocalizedException(
148+
sprintf(__('Error while generating js translation dictionary: "%s"'), error_get_last())
139149
);
140150
}
141151
}

0 commit comments

Comments
 (0)