Reputation: 446
Maybe someone can help me with this. Using the Microsoft developer api for translation text will output for example this text in English , "This email address is already registered!" to French like this "Cette adresse email est déjà enregistrée !" which really should be like this: "Cette adresse email est déjà enregistrée!". Is there a way to fix this. My simple script is this in php:
public function translate($word, $from, $to)
{
//retrieve token
$access_token = $this->get_access_token();
$url = 'http://api.microsofttranslator.com/V2/Http.svc/Translate?text='.urlencode($word).'&from='.$from.'&to='.$to;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:bearer '.$access_token,"Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
$rsp = curl_exec($ch);
$xmlObj = simplexml_load_string($rsp);
foreach((array)$xmlObj[0] as $val){
$translatedStr = $val;
}
return $translatedStr;
}
Upvotes: 0
Views: 187
Reputation: 188
Check this:
As it says there:
Simple: When you use curl it encodes the string to utf-8 you just need to decode them..
Description
string utf8_decode ( string $data )
This function decodes data , assumed to be UTF-8 encoded, to ISO-8859-1.
Upvotes: 1