Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento script to automate product-translations using the Yireo BingTranslate 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('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
You can’t perform that action at this time.