From a150d2485ec17687b83a444fa7ba4cac528e55f2 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Sun, 6 Aug 2017 14:35:53 +0600 Subject: [PATCH 1/5] Don't only replace \' but also \" with ' and " --- app/code/Magento/Translation/Model/Js/DataProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index 040b3fd211b99..389d48eea3088 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -139,7 +139,7 @@ protected function getPhrases($content) if ($result) { if (isset($matches[2])) { foreach ($matches[2] as $match) { - $phrases[] = str_replace('\\\'', '\'', $match); + $phrases[] = str_replace(["\'", '\"'], ["'", '"'], $match); } } } From c79b583422d994433f613355cf2e2ffb22c8d4e1 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Sun, 6 Aug 2017 14:36:46 +0600 Subject: [PATCH 2/5] Concatenate JS translations before translating them This enables support for $.mage.__("concatenating" + "strings"); --- app/code/Magento/Translation/Model/Js/DataProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index 389d48eea3088..67d594b65b0f5 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -134,7 +134,8 @@ protected function getPhrases($content) { $phrases = []; foreach ($this->config->getPatterns() as $pattern) { - $result = preg_match_all($pattern, $content, $matches); + $concatenatedContent = preg_replace('~(["\'])\s*?\+\s*?\1~', '', $content); + $result = preg_match_all($pattern, $concatenatedContent, $matches); if ($result) { if (isset($matches[2])) { From f9304714d9ba0959150c09be3eeb7670a776d342 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Sun, 6 Aug 2017 14:39:47 +0600 Subject: [PATCH 3/5] +: put all regexes in cdata tags --- app/code/Magento/Translation/etc/di.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml index 13a170a37ecf2..20f6fda4414e3 100644 --- a/app/code/Magento/Translation/etc/di.xml +++ b/app/code/Magento/Translation/etc/di.xml @@ -65,8 +65,8 @@ - ~\$\.mage\.__\((?s)[^'"]*?(['"])(.+?)\1(?s).*?\)~ - ~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~ + + From 87d4ba475f46c86ab4473f2d66a6c9c5ccf4456c Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Sun, 6 Aug 2017 14:40:24 +0600 Subject: [PATCH 4/5] Prevent translation string lookup from breaking on \' or \" with a negative lookbehind --- app/code/Magento/Translation/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml index 20f6fda4414e3..69e57c962a8fa 100644 --- a/app/code/Magento/Translation/etc/di.xml +++ b/app/code/Magento/Translation/etc/di.xml @@ -65,7 +65,7 @@ - + From 5ae47df31fc186b60053e7318a1bcb5091902239 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Sun, 6 Aug 2017 14:41:34 +0600 Subject: [PATCH 5/5] Support $.mage.__('') as well as jQuery.mage.__('') --- app/code/Magento/Translation/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml index 69e57c962a8fa..c10619fbf74ae 100644 --- a/app/code/Magento/Translation/etc/di.xml +++ b/app/code/Magento/Translation/etc/di.xml @@ -65,7 +65,7 @@ - +