From 1a6200b913c69333927b9723eca215430713fdae Mon Sep 17 00:00:00 2001 From: Hayder Sharhan <hsharhan@ebay.com> Date: Wed, 16 Mar 2016 16:43:30 -0500 Subject: [PATCH] MAGETWO-50411: incorrect output of collect phrases - generates incorrect CSV file - Changed regex to simple str_replace. - Added explanation comment --- .../Magento/Framework/Phrase/Renderer/Translate.php | 3 ++- setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php index 9cc79b5fab2..910b1a7587b 100644 --- a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php +++ b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php @@ -49,7 +49,8 @@ class Translate implements RendererInterface public function render(array $source, array $arguments) { $text = end($source); - $text = preg_replace('/([^\\\\])(\\\\")/', '$1"', $text); + /* If phrase contains escaped double quote then use translation for phrase with non-escaped quote */ + $text = str_replace('\"', '"', $text); try { $data = $this->translator->getData(); diff --git a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php index 4e6c4359183..56cbd751fc6 100644 --- a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php +++ b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php @@ -267,12 +267,14 @@ class Phrase private function getCompiledString($string) { $encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE; - //find all occurrences of ' and ", with no \ before it. + /* Find all occurrences of ' and ", with no \ before it for concatenation */ preg_match_all('/[^\\\\]' . $encloseQuote . '|' . $encloseQuote . '[^\\\\]/', $string, $matches); if (count($matches[0])) { $string = preg_replace('/([^\\\\])' . $encloseQuote . ' ?\. ?' . $encloseQuote . '/', '$1', $string); } - $string = preg_replace('/([^\\\\])(\\\\")/', '$1"', $string); + /* Remove all occurrences of escaped double quote because it is not desirable in csv file. + Translation for such phrases will use translation for phrase without escaped quote. */ + $string = str_replace('\"', '"', $string); return $string; } } -- GitLab