PHP: Bing Translate API как альтернатива Google Translate API
Взято с http://www.som3on3.com/programming/php/php-bing-translate-api/
<?php define('BING_API', 'YOUR_API_KEY'); function loadData($url, $ref = false) { $chImg = curl_init($url); curl_setopt($chImg, CURLOPT_RETURNTRANSFER, true); curl_setopt($chImg, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0"); if ($ref) { curl_setopt($chImg, CURLOPT_REFERER, $ref); } $curl_scraped_data = curl_exec($chImg); curl_close($chImg); return $curl_scraped_data; } function translate($text, $from = 'en', $to = 'fr') { $data = loadData('http://api.bing.net/json.aspx?AppId=' . BING_API . '&Sources=Translation&Version=2.2&Translation.SourceLanguage=' . $from . '&Translation.TargetLanguage=' . $to . '&Query=' . urlencode($text)); $translated = json_decode($data); if (sizeof($translated) > 0) { if (isset($translated->SearchResponse->Translation->Results[0]->TranslatedTerm)) { return $translated->SearchResponse->Translation->Results[0]->TranslatedTerm; } else { return false; } } else { return false; } } ?>
Использование:
<?php echo translate('Hello World', 'en', 'fr'); ?>
Еще по теме: http://habrahabr.ru/blogs/javascript/133940/