6
6
7
7
namespace Magento \Translation \Model \Js ;
8
8
9
+ use Magento \Framework \Exception \LocalizedException ;
10
+
9
11
/**
10
12
* DataProvider for js translation
13
+ *
14
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11
15
*/
12
16
class DataProvider implements DataProviderInterface
13
17
{
@@ -103,9 +107,15 @@ public function getData($themePath)
103
107
$ read = $ this ->fileReadFactory ->create ($ filePath [0 ], \Magento \Framework \Filesystem \DriverPool::FILE );
104
108
$ content = $ read ->readAll ();
105
109
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
+ );
109
119
}
110
120
}
111
121
}
@@ -118,7 +128,7 @@ public function getData($themePath)
118
128
*
119
129
* @param string $content
120
130
* @return string[]
121
- * @throws \Exception
131
+ * @throws \Magento\Framework\ Exception\LocalizedException
122
132
*/
123
133
protected function getPhrases ($ content )
124
134
{
@@ -134,8 +144,8 @@ protected function getPhrases($content)
134
144
}
135
145
}
136
146
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 ())
139
149
);
140
150
}
141
151
}
0 commit comments