1

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("خوله محمد احمد");

enter image description here

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:

enter image description here

But as you notice from the picture "khwlh muhamad ahmad" next to red arrow is what I want!

How can I achieve this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
omarzKH
  • 23
  • 11
  • Do you want to get people names in latin? [Related](https://stackoverflow.com/q/1841874/1997232). – Sinatr Mar 04 '21 at 12:48
  • I want to translate Arabic Names to English – omarzKH Mar 04 '21 at 12:49
  • I don't know arabic. Can you use [this solution](https://stackoverflow.com/a/57081642/1997232)? – Sinatr Mar 04 '21 at 12:53
  • Does this answer your question? [Getting pronunciation of a word using Google Translate API](https://stackoverflow.com/questions/24100983/getting-pronunciation-of-a-word-using-google-translate-api) – Peter Csala Mar 04 '21 at 13:05
  • @PeterCsala unfortunately no – omarzKH Mar 04 '21 at 13:25
  • @sinatr unfortunately no – omarzKH Mar 04 '21 at 13:25
  • @omarzKH, I am curiouss why dictionary is not a solution? Can you provide some details? I doubt google api providing [transliteration](https://en.wikipedia.org/wiki/Transliteration) together with translation, those are different topics and I expect transliteration to be a much simpler problem. – Sinatr Mar 04 '21 at 13:30
  • Wiki mentioned: *"A simple example of difficulties in transliteration is the Arabic letter qāf. It is pronounced, in literary Arabic, approximately like English [k], except that the tongue makes contact not on the soft palate but on the uvula, but the pronunciation varies between different dialects of Arabic. The letter is sometimes transliterated into "g", sometimes into "q" and rarely even into "k" in English"*. Is this the issue? – Sinatr Mar 04 '21 at 13:32
  • With names you will run into trouble anyway, because a good dictionary (lexicon) is difficult to set up for names. Actually if you want to go from Arab to Latin notation, the easiest solution may be to implement substitution rules for most common cases, see https://en.wikipedia.org/wiki/Romanization_of_Arabic – Goodies Mar 04 '21 at 14:58

0 Answers0