Arkadaşlar merhaba daha önce çalışan bing translator scriptim şuan çalışmıyor.
Aynı sistemin Google olanı var o çalışıyor.
Galiba buradaki ufak bir değişiklik oldu Bing tarafından.
Anlayan bir arkadaş bakabilir mi acaba?
<?php
include "Unirest.php";
$text = $_POST['text'];
$source = $_POST['source'];
$target = $_POST['target'];
if (!isset($text) || !isset($source) || !isset($target)) {
echo "Can't translate";
} else {
$outText = BingTranslate($text, $source, $target);
echo $outText;
}
function BingTranslate($text, $source, $target) {
$appID = getAppIDBing();
$text = str_replace(""", "", $text);
$text = str_replace("n", ". ", $text);
//Phát hiện ngôn ngữ tự động
if ($source == "auto") {
$source = "";//Trong Bing để source = "" thì nó hiểu là sẽ tự phát hiện ngôn ngữ.
}
$url = "http://api.microsofttranslator.com/v2/ajax.svc/TranslateArray2?appId="" . $appID . """
. "&texts=["" . urlencode($text) . ""]&from="" . $source . ""&to="" . $target . ""&options={}&onerror=onError_5&_=1429904869822";
$content = UnirestRequest::get($url, null, null);
if ($content->code != "200") {
return "";
}
$body = $content->raw_body;
$temp = explode("TranslatedText":"", $body)[1];
$trans = explode("","", $temp)[0];
return $trans;
}
function getAppIDBing() {
$url = "http://www.bing.com/translator/dynamic/225277/js/LandingPage.js";
$content = UnirestRequest::get($url, null, null);
$body = $content->raw_body;
$temp = explode("appId:"", $body)[1];
$temp = explode(""", $temp)[0];
return $temp;
}