I'm working on a project (Names Translator ) in C#.
This is my code:
public String Translate(String word)
{
var toLanguage = "en";//English
var fromLanguage = "ar";//Deutsch
var url = $"https://translate.googleapis.com/translate_a/single?client=gtx&sl={fromLanguage}&tl={toLanguage}&dt=t&q={HttpUtility.UrlEncode(word)}";
var webClient = new WebClient
{
Encoding = System.Text.Encoding.UTF8
};
var result = webClient.DownloadString(url);
try
{
result = result.Substring(4, result.IndexOf("\"", 4, StringComparison.Ordinal) - 4);
return result;
}
catch
{
return "Error";
}
and it works for most names, but sometimes Google Translate translates the names literally, for example
string result=Translate("خوله محمد احمد");
The result will be
He was authorized by Mohamed Ahmed
"خوله" =he was authorized
On the Google Translate website it gives me the same wrong translation:
But as you notice from the picture "khwlh muhamad ahmad" next to red arrow is what I want!
How can I achieve this?