From cc788013bc147d76754ab5a532bba4e4b3d9a61c Mon Sep 17 00:00:00 2001 From: kjavitz Date: Thu, 5 Nov 2020 17:19:04 +0545 Subject: [PATCH] fix dev key (disabled) --- README.md | 6 +++++- translate.php | 3 +++ translateclass.php | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11ec3ce..aa240e9 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,9 @@ Translates Magento 2 CSV files from one language to another using Google Translate For information on usage please visit Magento 2 Google Translate Info at Sales Igniter. -Updated November 1, 2016 +###Changelog +November 5, 2020 +- Updated the Google Api code, fixed issue with %1 replacements in .csv file + +November 1, 2016 - Now supports translating to multiple languages at the same time diff --git a/translate.php b/translate.php index 484294d..9916e48 100644 --- a/translate.php +++ b/translate.php @@ -54,6 +54,9 @@ //var_dump($translated); ?> + + Magento 2 i18n Module CSV Google Translate App + diff --git a/translateclass.php b/translateclass.php index 61272ca..131979a 100644 --- a/translateclass.php +++ b/translateclass.php @@ -76,7 +76,17 @@ public function processTranslationByRow($reader, $destinationLanguage){ } if(($curRow != 0 && (($curRow % $this->linesToProcess) == 0)) || // if we are in a multiple of lines to process (($curRow + 1) == $totalRows)){ // - $translationsArray = $this->client->translateBatch($textToTranslateArray, ['source' => $this->sourcelanguage, 'target' => $destinationLanguage ]); + $translationsArray = $this->client->translateBatch($textToTranslateArray, + ['format' => 'text', 'source' => $this->sourcelanguage, 'target' => $destinationLanguage ]); + // Google translate changes %1 to (space)% 1 which messes up variable replacement, needs to stay %1 + foreach($translationsArray as $key => $value){ + $translationsArray[$key]['text'] = str_ireplace('% 1', ' %1', $translationsArray[$key]['text']); + $translationsArray[$key]['text'] = str_ireplace('% 2', ' %2', $translationsArray[$key]['text']); + $translationsArray[$key]['text'] = str_ireplace('% 3', ' %3', $translationsArray[$key]['text']); + $translationsArray[$key]['text'] = str_ireplace('" %1"', '"%1"', $translationsArray[$key]['text']); + $translationsArray[$key]['text'] = str_ireplace('" %2"', '"%2"', $translationsArray[$key]['text']); + $translationsArray[$key]['text'] = str_ireplace('" %3"', '"%3"', $translationsArray[$key]['text']); + } $translatedTextArray = array_merge($translatedTextArray, $translationsArray); $textToTranslateArray = []; // reset }