From aad62df2f1fdbc211716ed14144014f25fce6f76 Mon Sep 17 00:00:00 2001 From: Bart Delvaux Date: Mon, 6 Jul 2015 17:24:55 +0200 Subject: [PATCH 1/3] The strings of static html files (like minicart in checkout) are not loaded in the js-translate.json With this fix, these files will be in the list and could be translated trough the jstranslator function --- .../Translation/Model/Js/DataProvider.php | 11 +++++++- app/code/Magento/Translation/etc/di.xml | 1 + .../Magento/Framework/App/Utility/Files.php | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index c99c8eeac6708..6c53d27539318 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -72,6 +72,11 @@ public function getData($themePath) $dictionary = []; $files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath); + + foreach ($this->filesUtility->getStaticHtmlFiles($this->appState->getAreaCode(), $themePath) as $staticFile) { + $files[] = $staticFile; + } + foreach ($files as $filePath) { $content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0])); foreach ($this->getPhrases($content) as $phrase) { @@ -99,7 +104,11 @@ protected function getPhrases($content) $result = preg_match_all($pattern, $content, $matches); if ($result) { - $phrases = array_merge($phrases, $matches[1]); + if (isset($matches[1])) { + foreach ($matches[1] as $match) { + $phrases[] = $match; + } + } } if (false === $result) { throw new \Exception( diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml index 0c1b01ddd6a13..615d565f7419e 100644 --- a/app/code/Magento/Translation/etc/di.xml +++ b/app/code/Magento/Translation/etc/di.xml @@ -58,6 +58,7 @@ ~\$\.mage\.__\([\'|\"](.+?)[\'|\"]\)~ + ~\$t\([\'|\"](.+?)[\'|\"]\)~ diff --git a/lib/internal/Magento/Framework/App/Utility/Files.php b/lib/internal/Magento/Framework/App/Utility/Files.php index 275a2bfdf0f4c..b80400c866bb5 100644 --- a/lib/internal/Magento/Framework/App/Utility/Files.php +++ b/lib/internal/Magento/Framework/App/Utility/Files.php @@ -522,6 +522,34 @@ public function getJsFiles($area = '*', $themePath = '*/*', $namespace = '*', $m return $result; } + /** + * Returns list of Static HTML files in Magento + * + * @param string $area + * @param string $themePath + * @param string $namespace + * @param string $module + * @return array + */ + public function getStaticHtmlFiles($area = '*', $themePath = '*/*', $namespace = '*', $module = '*') + { + $key = $area . $themePath . $namespace . $module . __METHOD__ . $this->_path; + if (isset(self::$_cache[$key])) { + return self::$_cache[$key]; + } + $files = self::getFiles( + [ + "{$this->_path}/app/code/{$namespace}/{$module}/view/{$area}/web/template", + "{$this->_path}/app/design/{$area}/{$themePath}/web/template", + "{$this->_path}/app/design/{$area}/{$themePath}/{$module}/web/template" + ], + '*.html' + ); + $result = self::composeDataSets($files); + self::$_cache[$key] = $result; + return $result; + } + /** * Get list of static view files that are subject of Magento static view files preprocessing system * From b63aa5f7a3f087e5a4811b7a411fb623bfb0741b Mon Sep 17 00:00:00 2001 From: Bart Delvaux Date: Thu, 16 Jul 2015 12:23:20 +0200 Subject: [PATCH 2/3] Fix unit test --- app/code/Magento/Translation/Model/Js/DataProvider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index 6c53d27539318..3d7e1660026a1 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -70,10 +70,11 @@ public function __construct(State $appState, Config $config, Filesystem $filesys public function getData($themePath) { $dictionary = []; + $areaCode = $this->appState->getAreaCode(); - $files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath); + $files = $this->filesUtility->getJsFiles($areaCode, $themePath); - foreach ($this->filesUtility->getStaticHtmlFiles($this->appState->getAreaCode(), $themePath) as $staticFile) { + foreach ($this->filesUtility->getStaticHtmlFiles($areaCode, $themePath) as $staticFile) { $files[] = $staticFile; } From 606d28d8e101dadce9f60c5d8d0864375f50b3ec Mon Sep 17 00:00:00 2001 From: Bart Delvaux Date: Thu, 16 Jul 2015 14:02:43 +0200 Subject: [PATCH 3/3] Fix unit test --- app/code/Magento/Translation/Model/Js/DataProvider.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index 3d7e1660026a1..7a66f0858982b 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -73,9 +73,12 @@ public function getData($themePath) $areaCode = $this->appState->getAreaCode(); $files = $this->filesUtility->getJsFiles($areaCode, $themePath); + $staticHtmlFiles = $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath); - foreach ($this->filesUtility->getStaticHtmlFiles($areaCode, $themePath) as $staticFile) { - $files[] = $staticFile; + if (is_array($staticHtmlFiles)) { + foreach ($staticHtmlFiles as $staticFile) { + $files[] = $staticFile; + } } foreach ($files as $filePath) {