Skip to content

Instantly share code, notes, and snippets.

@yireo
Created November 3, 2013 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yireo/7287966 to your computer and use it in GitHub Desktop.
Save yireo/7287966 to your computer and use it in GitHub Desktop.
Magento script to automate product-translations using the Yireo GoogleTranslate extension
<?php
// Basic settings
$storeCodes = array('french', 'german', 'danish', 'dutch');
$productAttributes = array('name', 'short_description', 'description');
// Initialize Magento
require_once 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// Load the product-collection
$productCollection = Mage::getModel('catalog/product')->getCollection();
if(!empty($productIds)) $productCollection->addAttributeToFilter('entity_id', array('in' => $productIds));
// Loop through the product-collection
$totalChars = 0;
foreach($productCollection as $product) {
$productTranslator = Mage::getModel('googletranslate/product');
$productTranslator->translate($product, $productAttributes, $storeCodes);
$totalChars = $totalChars = $productTranslator->getCharCount();
}
$costPerCharacter = (float)6000/1000000000;
$translationCost = number_format($costPerCharacter * $totalChars, 2);
echo "Total amount of characters: ".$totalChars."\n";
echo 'Estimated costs USD $'.$translationCost." (".$totalChars." characters)\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment