I am calling google translate with the below code (I used Curl to
allow me to translate more than 500 characters). However, I am having
issues with the Spanish special characters not being returned
correctly.
Here is an example of what is being returned:
ó instead of ó
ó instead of ó
á instead of á
ñ instead of ñ
etc.
Currently, I have to do a string replace in PHP to clean up the
garbage. I'd rather not hard code this though. Has anyone ran into
this issue before?
function translate($transText,$tlang){
define('POSTURL', '
http://ajax.googleapis.com/ajax/services/
language/translate');
// INITIALIZE ALL VARS
$ch='';
$Rec_Data='';
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,
'q='. urlencode($transText). '&v=1.0'. '&langpair=%7C' . $tlang);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN
HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE
CONTENTS OF THE CALL
$rec_Data = json_decode(curl_exec($ch), true);
return $rec_Data['responseData']['translatedText'];
}