Exemple #1
0
        protected override string Translate(string value, string fromLanguage, string toLanguage, string fromApiLanguage, string toApiLanguage)
        {
            using (WebClient webClient = new WebClient())
            {
                string url = string.Format("https://translation.babylon-software.com/translate/babylon.php?v=1.0&q={0}&langpair={1}|{2}&callback=babylonTranslator.callback&context=babylon.0.3._babylon_api_response",
                                           HttpUtility.UrlEncode(value), languageIds[fromApiLanguage], languageIds[toApiLanguage]);

                webClient.Proxy    = null;
                webClient.Encoding = Encoding.UTF8;
                webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded; charset=UTF-8";
                string json = webClient.DownloadStringAwareOfEncoding(url);
                json = json.Substring(json.IndexOf('{'));
                json = json.Substring(0, json.LastIndexOf('}') + 1);
                TranslateResponse response = JSONSerializer <TranslateResponse> .DeSerialize(json);

                string result = HttpUtility.UrlDecode(response.translatedText);
                //string result = HttpUtility.HtmlDecode(response.translatedText);
                return(result);
            }
        }