Created
November 3, 2013 09:17
-
-
Save yireo/7287966 to your computer and use it in GitHub Desktop.
Magento script to automate product-translations using the Yireo GoogleTranslate extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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