0

I am trying to use the Google translator for some sentence translation(English to Urdu also not working with Arabic) but I am stuck with a problem.

when i click button it returns some symbols. i used this answer link getting the translated language using google translator in winform apps

But it's not working as i require. I think the problem is with UTF Encoding. UTF16 is not supported. I used Unicode but it's also not working. I also have installed the desired language in my PC.

Any help is appreciated. Thank you.

            string input = "How are you";
            string languagePair = "en|ur";

            string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
            WebClient webClient = new WebClient();
            webClient.Encoding = System.Text.Encoding.UTF8;
            string result = webClient.DownloadString(url);
            result = result.Substring(result.IndexOf("<span title=\"") + "<span title=\"".Length);
            result = result.Substring(result.IndexOf(">") + 1);
            result = result.Substring(0, result.IndexOf("</span>"));
            result = HttpUtility.HtmlDecode(result.Trim());

            MessageBox.Show(result);
uniqueSolutions
  • 143
  • 2
  • 8
  • 3
    How specifically is it *not working as I require*? If you don't explain to us what you require, and how specifically your code is not meeting those requirements, how are we supposed to help? – Ken White Aug 14 '18 at 00:51
  • See also https://stackoverflow.com/questions/18697962/how-to-get-utf-16-byte-array – Jay Aug 14 '18 at 00:59
  • Read [these notes](https://stackoverflow.com/questions/49846392/kanji-characters-from-webclient-html-different-from-actual-kanji-in-website?answertab=active#tab-top) about WebClient and Encoding. See whether that method works for you. In short, WebClient uses the Encoding provided by the initializer or, if none is provided, the default encoding (local CodePage). When downloading an `html` page, you need to encode the content using the original encoding, not a generic one. – Jimi Aug 14 '18 at 01:04
  • @KenWhite As i said in my question that it's showing some symbols instead of Urdu/Arabic characters – uniqueSolutions Aug 14 '18 at 11:27

0 Answers0