From 2ddce43dcb86893f110aa8abb2bd6cc95d83d26f Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 20 Feb 2015 20:38:53 +0000 Subject: [PATCH] 0.6.0 * support for debug and dry run was added to the fballiano_full_catalog_translate.php shell script --- CHANGELOG.md | 3 +++ shell/fballiano_full_catalog_translate.php | 24 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c4417b..6080077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +0.6.0 +* support for debug and dry run was added to the fballiano_full_catalog_translate.php shell script + 0.5.0 ----- * support for custom translation command was introduced diff --git a/shell/fballiano_full_catalog_translate.php b/shell/fballiano_full_catalog_translate.php index d57e95b..0b843c0 100644 --- a/shell/fballiano_full_catalog_translate.php +++ b/shell/fballiano_full_catalog_translate.php @@ -35,9 +35,14 @@ class Fballiano_FullCatalogTranslate_Shell extends Mage_Shell_Abstract protected $ws_url = "https://www.googleapis.com/language/translate/v2"; protected $attributes_to_translate = null; protected $datapump = null; + protected $debug_mode = false; + protected $dry_run = false; public function run() { + $this->debug_mode = $this->getArg("debug"); + $this->dry_run = $this->getArg("dry"); + if ($this->dry_run) $this->debug_mode = true; $this->helper = Mage::helper("fballiano_fullcatalogtranslate"); $this->translation_system = $this->helper->getTranslationSystem(); $this->attributes_to_translate = $this->helper->getAttributesToTranslate(); @@ -101,6 +106,7 @@ public function run() $row = $product->getData(); echo "Translating {$row["sku"]} from {$this->language_source} to {$this->language_dest}... "; + if ($this->debug_mode) echo "\n"; $translated_row = array(); $translated_row["store"] = (string)$this->store_dest; $translated_row["sku"] = (string)$row["sku"]; @@ -109,8 +115,11 @@ public function run() if (strlen($row[$attribute])) { $translated_row[$attribute] = $this->translateString($row[$attribute]); } + if ($this->debug_mode) { + echo "\t[$attribute] [{$row[$attribute]}] -> [{$translated_row[$attribute]}]\n"; + } } - $this->datapump->ingest($translated_row); + if (!$this->dry_run) $this->datapump->ingest($translated_row); echo "OK\n"; } @@ -123,6 +132,7 @@ public function productCollectionWalkCallback($args) { $row = $args["row"]; echo "Translating {$row["sku"]} from {$this->language_source} to {$this->language_dest}... "; + if ($this->debug_mode) echo "\n"; $translated_row = array(); $translated_row["store"] = $this->store_dest; $translated_row["sku"] = $row["sku"]; @@ -131,9 +141,12 @@ public function productCollectionWalkCallback($args) if (strlen($row[$attribute])) { $translated_row[$attribute] = $this->translateString($row[$attribute]); } + if ($this->debug_mode) { + echo "\t[$attribute] [{$row[$attribute]}] -> [{$this->language_dest} {$translated_row[$attribute]}]\n"; + } } - $this->datapump->ingest($translated_row); + if (!$this->dry_run) $this->datapump->ingest($translated_row); echo "OK\n"; } @@ -142,6 +155,7 @@ public function translateString($string) switch ($this->translation_system) { case "googletranslate": $ws_url = "{$this->ws_url}&q=" . urlencode($string); + if ($this->debug_mode) echo "\t{$ws_url}\n"; $translated = json_decode(file_get_contents($ws_url), true); return (string)$translated["data"]["translations"][0]["translatedText"]; case "custom": @@ -150,6 +164,7 @@ public function translateString($string) array($this->language_source, $this->language_dest, $string), $this->command ); + if ($this->debug_mode) echo "\t{$command}\n"; return shell_exec($command); } } @@ -158,7 +173,10 @@ public function usageHelp() { return <<