Tradurre brevi testi, Translate short texts
Posted: Wed Jun 23, 2021 6:23 am
Salve, in un mio programma devo inviare email in italiano ed inglese. Pensavo di tradurre il testo con una chiamata a google translator, con un codice più o meno così:
Hi, in one of my programs I have to send emails in Italian and English. I was thinking of translating the text with a call to google translator, with some code like this:
#using System.Net
FUNCTION Start( ) AS VOID
LOCAL input_language AS STRING
LOCAL output_language AS STRING
LOCAL result AS STRING
input_language := "it"
output_language := "en"
result := TranslateText("Buongiorno", input_language + "|" + output_language)
System.Console.WriteLine(result)
RETURN
FUNCTION TranslateText(input AS STRING,languagePair AS STRING) AS STRING
LOCAL url AS STRING
LOCAL oWebClient AS WebClient
LOCAL result AS STRING
url := String.Format("https://translate.google.it/?text={0}&langpair={1}", input, languagePair)
oWebClient := WebClient{}
oWebClient:Encoding := System.Text.Encoding.Default
result := oWebClient:DownloadString(url)
result := result:Substring(result:IndexOf("data-text"))
result := result:Replace("data-text=","")
result := result:Substring(0, result:IndexOf("data-crosslingual-hint"))
result := result:Replace(Chr(34),"")
RETURN result
Ma torna sempre il testo italiano.
But the Italian text always comes back.
Grazie
thank you
Hi, in one of my programs I have to send emails in Italian and English. I was thinking of translating the text with a call to google translator, with some code like this:
#using System.Net
FUNCTION Start( ) AS VOID
LOCAL input_language AS STRING
LOCAL output_language AS STRING
LOCAL result AS STRING
input_language := "it"
output_language := "en"
result := TranslateText("Buongiorno", input_language + "|" + output_language)
System.Console.WriteLine(result)
RETURN
FUNCTION TranslateText(input AS STRING,languagePair AS STRING) AS STRING
LOCAL url AS STRING
LOCAL oWebClient AS WebClient
LOCAL result AS STRING
url := String.Format("https://translate.google.it/?text={0}&langpair={1}", input, languagePair)
oWebClient := WebClient{}
oWebClient:Encoding := System.Text.Encoding.Default
result := oWebClient:DownloadString(url)
result := result:Substring(result:IndexOf("data-text"))
result := result:Replace("data-text=","")
result := result:Substring(0, result:IndexOf("data-crosslingual-hint"))
result := result:Replace(Chr(34),"")
RETURN result
Ma torna sempre il testo italiano.
But the Italian text always comes back.
Grazie
thank you