im working on a project (Names Translator ) in c# ASP.NET
this is my code
- public String Translate(String word)
- {
- var toLanguage = "en";
- var fromLanguage = "ar";
- 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 its works for most names
but sometimes "google translate" translate the names literally
for example
He was authorized by Mohamed Ahmed
????=he was authorized
it translate the name literally
when i go to google translate and translate the same name
it gives me the same wrong translation
but as you notice from the picture "khwlh muhamad ahmad next to red arrow" appear below is what i want !
how can i achive this ?
i need help ! thank you