PHP
- 2 ответа
- 0 вопросов
1
Вклад в тег
<?php
function i18n_translate($s_text, $s_lang, $d_lang) {
$post_data['q'] = $s_text;
$post_data['langpair'] = $s_lang."|".$d_lang;
$query = http_build_query($post_data);
$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, 0);
curl_setopt($c, CURLOPT_POSTFIELDS, $query);
$b = curl_exec($c);
curl_close($c);
$json = json_decode($b, true);
if ($json['responseStatus'] != 200) return false;
return html_entity_decode($json['responseData']['translatedText'], ENT_QUOTES);
}