I ask for help. I'm blocked with this issue. Maybe it's a silly question but I don't how do it.
I need call this URL http://mymemory.translated.net/api/get? ... pair=en|it
Where "red" is the text to translate, in this case from English to Italian. Since Google Translator isn't free this service from mymemory is a cool alternative.
I put this into a PHP script that return the translated text directly from the JSON that the URL return.
http://31.193.137.141/trans2.php?value=zimmer
In this case is from Deutsch to Italian.
My problem is that if the vaule that is passed by POST to the URL don't have any accented char they work perfectly, but if have any accented char don't work. I know that is a issue with the encode way to send the text.
Code: Select all
put "http://api.mymemory.translated.net/get?q=" & urlencode(utf8encode(tItem)) & "&langpair=" & tOrigen & "|" & tDestino into tURL
put URL tURL into tResult
Code: Select all
put "http://31.193.137.141/trans2.php" into tURL
put "value" & "=" & tfrase into myPostData
put myPostData & " --> " & urlencode(utf8encode(tfrase)) & cr after fld "f_log"
Post myPostData to URL tURL
put it into tResult
put utf8decode(tResult) & cr after fld "f_log"
put "----" & cr after fld "f_log"
put tItem & "->" & utf8decode(tResult) & cr after fld "f_translated"
PHP Script
Code: Select all
<?php
header('Content-type: text/plain; charset=utf-8');
error_reporting(E_ALL);
if (isset($_POST['value']))
{
$valor=($_POST['value']);
}
else
{
$valor=($_GET['value']);
}
echo "http://mymemory.translated.net/api/get?q=".$valor."&langpair=de|it"."\n\n";
// creating curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mymemory.translated.net/api/get?q=".$valor."&langpair=de|it");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$output = curl_exec($ch);
curl_close($ch);
$translate_it=json_decode($output,true);
$varuno = $translate_it['responseData']['translatedText'];
echo $varuno;
?>
Salut,
Josep M