Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
* support for debug and dry run was added to the fballiano_full_catalog_translate.php shell script
  • Loading branch information
Fabrizio Balliano committed Feb 20, 2015
1 parent 68150cc commit 2ddce43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 21 additions & 3 deletions shell/fballiano_full_catalog_translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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"];
Expand All @@ -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";
}

Expand All @@ -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"];
Expand All @@ -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";
}

Expand All @@ -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":
Expand All @@ -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);
}
}
Expand All @@ -158,7 +173,10 @@ public function usageHelp()
{
return <<<USAGE
Usage: php -f fballiano_full_catalog_translate.php source_store_view_code target_store_view_code
Usage:\tphp -f fballiano_full_catalog_translate.php source_store_view_code target_store_view_code [-debug] [-dry]
-debug\tshows every call to traslation systems and the results
-dry\ttranslates everything (automatically enables debug also) but do not save anything on the database
USAGE;
}
Expand Down

0 comments on commit 2ddce43

Please sign in to comment.