Skip to content

Commit

Permalink
fix dev key (disabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjavitz committed Nov 5, 2020
1 parent 90ed48b commit cc78801
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
Translates Magento 2 CSV files from one language to another using Google Translate
For information on usage please visit <a href="https://rentalbookingsoftware.com/magento-2-csv-file-translator-using-google-translate-api/">Magento 2 Google Translate Info</a> 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
3 changes: 3 additions & 0 deletions translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
//var_dump($translated);
?>
<html>
<head>
<title>Magento 2 i18n Module CSV Google Translate App</title>
</head>
<body>
<link href="vendor/twbs/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
Expand Down
12 changes: 11 additions & 1 deletion translateclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cc78801

Please sign in to comment.