Answer the question
In order to leave comments, you need to log in
Google translate
Let's run this script:
<?php
// берём чешское слово 'Koláče' (пироги), подготавливаем к передаче через URL
$text = urlencode('Koláče');
// формируем запрос
$query = "http://translate.google.com/translate_a/t?client=x&text={$text}&sl=cs&tl=en";
// который в итоге выглядит так:
// http://translate.google.com/translate_a/t?client=x&text=Kol%C3%A1%C4%8De&sl=cs&tl=en
// посылаем для перевода
// этот кусок взял отсюда:
//http://stackoverflow.com/questions/542046/php-file-get-contentsloc-fails
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $query);
$response = curl_exec($curl);
curl_close($curl);
// но вместо него можно и проще, результат будет одинаков:
// $response = file_get_contents($query);
echo $response;
?>
{"sentences":[{
"trans":"Kol\u0102\u0104\u00C4 e",
"orig":"Kol\u0102\u0104\u00C4 e",
"translit":"",
"src_translit":""
}],"src":"cs","server_time":2}
{"sentences":[{
"trans":"Pies",
"orig":"Koláče",
"translit":"",
"src_translit":""
}],"src":"cs","server_time":41}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question