Перевожу:
exec("SET NAMES 'UTF8';");
$sql="select identifier from main._translations where del=false group by identifier";
$res = NULL;
try
{
$res = $db->query($sql);
}catch (Exception $e)
{
echo $e->getMessage();
}
if($res!=NULL && $res->rowCount()>0) {
while ($row = $res->fetch(PDO::FETCH_NUM)) {
//Выбираю перевод на русском
$type="NULL";
$translate="";
$sql="select translation,type from main._translations where identifier='".$row[0]."' and language_id=(select id from main._languages where short_name='ru');";
$res2 = NULL;
try
{
$res2 = $db->query($sql);
}catch (Exception $e)
{
echo $e->getMessage();
}
if($res2!=NULL && $res2->rowCount()>0) {
while ($row2 = $res2->fetch(PDO::FETCH_NUM)) {
$translate=$row2[0];
if($row2[1]===true) $type='true';
if($row2[1]===false) $type='false';
}
}
if($translate!=''){
$sql="select l.*,(select translation from main._translations t where t.del=false and t.language_id=l.id and identifier='".$row[0]."' limit 1) as translation from main._languages l where l.del=false;";
$res3 = NULL;
try
{
$res3 = $db->query($sql);
}catch (Exception $e)
{
echo $e->getMessage();
}
if($res3!=NULL && $res3->rowCount()>0) {
while ($row3 = $res3->fetch(PDO::FETCH_ASSOC)) {
//$translate=$row3[0];
if($row3['translation']==''){ //Если не переведён то пытаюсь перевести
echo 'short_name='.$row3['short_name'].' identifier='.$row[0].' text='.$translate.'
';
$myObj = new stdClass();
$myObj->target = $row3['short_name'];
$myObj->q = array($translate);
$json=json_encode($myObj);
//$json='{"q": ["Hello world", "My name is Jeff"], "target": "de"}';
echo $json."
";
$json=getURLText("https://translation.googleapis.com/language/translate/v2?key=AIzaSyAOtc8E9Yg0O1uuZ_0EMYgqFP7W3p_0LGI",$json);
echo $json;
echo "
";
/*
$myObj = new stdClass();
$myObj->sourceLanguageCode = "ru";
$myObj->targetLanguageCode = $row3['short_name'];
$myObj->contents = array($translate);
$json=json_encode($myObj);
$json='{"sourceLanguageCode": "en","targetLanguageCode": "ru","contents": ["Dr. Watson, come here!", "Bring me some coffee!"]}';
echo getURLText("https://translation.googleapis.com/v3/projects/AIzaSyAOtc8E9Yg0O1uuZ_0EMYgqFP7W3p_0LGI:translateText",$json);
*/
$myObj=json_decode($json); //{ "data": { "translations": [ { "translatedText": "km / h", "detectedSourceLanguage": "bg" } ] } }
if(!property_exists($myObj,'error')) {
echo '
';
$sql = "insert into main._translations(language_id,identifier,translation,type,auto)values(" . $row3['id'] . ",'" . $row[0] . "','" . addslashes($myObj->data->translations[0]->translatedText) . "',$type,true);";
echo $sql . '
';
try
{
$db->query($sql);
}catch (Exception $e)
{
echo $e->getMessage();
exit;
}
}
}
}
}
}
}
}
//http://translate.google.com/translate_a/t?client=x&text=hello&sl=en&tl=ru
//Если есть перевод с Русского то переводим с него если нет то с Английского
?>
Генерация