Skip to content

Instantly share code, notes, and snippets.

@yireo
Last active July 25, 2016 07:32
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/fca887bed2922f79acbaf1ae6bf96637 to your computer and use it in GitHub Desktop.
Save yireo/fca887bed2922f79acbaf1ae6bf96637 to your computer and use it in GitHub Desktop.
<?php
// Basic settings
$storeCodes = array('french');
$attributes = array('name', 'description');
$categoryIds = array(4);
// Initialize Magento
require_once 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// Load the category-collection
$categoryCollection = Mage::getModel('catalog/category')->getCollection();
if(!empty($categoryIds)) {
$categoryCollection->addAttributeToFilter('entity_id', array('in' => $categoryIds));
}
// Loop through the category-collection
$totalChars = 0;
foreach($categoryCollection as $category) {
$categoryTranslator = Mage::getModel('bingtranslate/category');
$categoryTranslator->translate($category, $attributes, $storeCodes);
$totalChars = $totalChars + $categoryTranslator->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