Magento: Translate using Google API

The meta data of my products were in English and the keywords on my website were not translated in French : I have decided to perform the translation in French using the Google Translate API. The Google Translate API is a paid service but the price is not expensive (20$ for 1000000 characters). I paid 1,50$ for 77562 bytes.

The Google API is available here:

You will find here how to proceed.

  1. Register your Google Project on the Google Developers Console
  2. Create your API key
  3. Download the PHP Google API
  4. Use my PHP script (must be modified).

You will find below an extract of my PHP script :

I will send the complete script to those who will donate (only 5€)


require_once 'Google/autoload.php';

$proxy = new SoapClient('https://......../api/v2_soap/?wsdl=1', array('trace' => 1, "user_agent" => "PHP Soap Client"));
$sessionId = $proxy->login(array('username' => 'your_user','apiKey' => 'apiKey'));


// Search Filter
$complexFilter = array(
		'complex_filter' => array(
						'key' => 'type',
						'value' => array(
								'key' => 'in',
								'value' => 'simple')


// Product List
$result = $proxy->catalogProductList((object)array('sessionId' => $sessionId->result, 'filters' => $complexFilter));


function getProductMeta(&$myproxy,&$mysessionid,$mystoreid,&$myproductid)
	$attributes = new stdclass();
	$attributes->attributes = array('meta_keyword','meta_title','meta_description');
	return $myproxy->catalogProductInfo((object)array('sessionId' => $mysessionid->result, 'productId' => &$myproductid, identifierType => 'id', 'attributes' => $attributes));

function GoogleTranslate($string)
	//echo "translate string=$stringn";
	$client = new Google_Client();
	$translateService = new Google_Service_Translate($client);
	$response=$translateService->translations->listTranslations($string, 'fr', array('source' => 'en'));;
	return $texte;

$ids=ParseProductsList($proxy,$sessionId,$result,$mystore, $ids);
foreach ($ids as $id)
	$meta=getProductMeta($proxy, $sessionId, $mystore, $id);
	// Translate
	// Title
	$meta_keyword_fr=GoogleTranslate(str_replace(',',' ',$meta_keyword));
	// Update store
	$result=updateDataStoreView($proxy, $sessionId,$id,array('meta_title' => $meta_title_fr,'meta_description' => $meta_description_fr,'meta_keyword' => str_replace(' ',',',}

// End Session
$proxy->endSession(array('sessionId' => $sessionId->result));


Et voila,

Nicolas Portais
Author Photographer



Ce contenu a été publié dans Anglais, Magento, avec comme mot(s)-clé(s) , , , , , , , , . Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Captcha (solve the arithmetic equation) * Time limit is exhausted. Please reload CAPTCHA.