Last active
December 17, 2015 00:49
-
-
Save yireo/5524123 to your computer and use it in GitHub Desktop.
Magento script to automate product-translations using the Yireo BingTranslate 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('bingtranslate/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