From 69eb715c4bb9fd7a42e70f9333fce3e53bbba5b2 Mon Sep 17 00:00:00 2001
From: Hayder Sharhan <hsharhan@ebay.com>
Date: Tue, 15 Mar 2016 23:20:53 -0500
Subject: [PATCH] MAGETWO-50411: incorrect output of collect phrases -
 generates incorrect CSV file

- Fixed problem with escaping in csv files.
---
 .../Magento/Setup/Console/Command/_files/expectedPhrases.csv  | 4 ++--
 lib/internal/Magento/Framework/Phrase/Renderer/Translate.php  | 1 +
 setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php     | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv
index b20a54d1bc0..65b9d12f213 100644
--- a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv
+++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv
@@ -15,6 +15,6 @@
 "string with placeholder in double quotes ""%1""","string with placeholder in double quotes ""%1"""
 "string with 'single quotes'","string with 'single quotes'"
 "string with placeholder in single quotes '%1'","string with placeholder in single quotes '%1'"
-"string with escaped \"double quotes\"","string with escaped \"double quotes\""
-"string with placeholder in escaped double quotes \"%1\"","string with placeholder in escaped double quotes \"%1\""
+"string with escaped ""double quotes""","string with escaped ""double quotes"""
+"string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1"""
 "string that\'s got an unclosed single quote in it","string that\'s got an unclosed single quote in it"
diff --git a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php
index 449b34d61c0..9cc79b5fab2 100644
--- a/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php
+++ b/lib/internal/Magento/Framework/Phrase/Renderer/Translate.php
@@ -49,6 +49,7 @@ class Translate implements RendererInterface
     public function render(array $source, array $arguments)
     {
         $text = end($source);
+        $text = preg_replace('/([^\\\\])(\\\\")/', '$1"', $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 e5c20133fa0..4e6c4359183 100644
--- a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php
+++ b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php
@@ -272,6 +272,7 @@ class Phrase
         if (count($matches[0])) {
             $string = preg_replace('/([^\\\\])' . $encloseQuote . ' ?\. ?' . $encloseQuote . '/', '$1', $string);
         }
+        $string = preg_replace('/([^\\\\])(\\\\")/', '$1"', $string);
         return $string;
     }
 }
-- 
GitLab