Beispiel #1
0
        private string YandexTranslate(string sentence, string inLang, string outLang)
        {
            string result = String.Empty;

            try
            {
                string _outLang = outLang;
                string _inLang  = inLang;

                string _baseUrl = @"https://translate.yandex.net/api/v1.5/tr.json/translate?lang={0}-{1}&key={2}";
                string url      = string.Format(_baseUrl, _inLang, _outLang, @"");

                var tmpResult = YandexWebRead.GetWebData(url, WebApi.WebReader.WebMethods.POST, "text=" + sentence);

                var resp = JsonConvert.DeserializeObject <YandexResponse>(tmpResult);

                if (resp.code == 200)
                {
                    for (int i = 0; i < resp.text.Count; i++)
                    {
                        result += resp.text[i] + " ";
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteLog(Convert.ToString(e));
            }

            return(result);
        }
Beispiel #2
0
        private string GoogleTranslate(string sentence, string inLang, string outLang)
        {
            string result = String.Empty;

            try
            {
                string _outLang = outLang;
                string _inLang  = inLang;

                string _baseUrl = "https://translate.google.com/m?hl=ru&sl={0}&tl={1}&ie=UTF-8&prev=_m&q={2}";
                string url      = string.Format(_baseUrl, _inLang, _outLang, sentence);

                var tmpResult = GoogleWebRead.GetWebData(url, WebApi.WebReader.WebMethods.GET);

                var rxMatch = GoogleRx.Match(tmpResult);

                if (rxMatch.Success)
                {
                    result = System.Net.WebUtility.HtmlDecode(rxMatch.Value);
                }
            }
            catch (Exception e)
            {
                Logger.WriteLog(Convert.ToString(e));
            }

            return(result);
        }
Beispiel #3
0
        private string MultillectTranslate(string sentence, string inLang, string outLang)
        {
            string result = String.Empty;

            try
            {
                string _outLang = outLang;
                string _inLang  = inLang;

                string _baseUrl = @"https://translate.multillect.com/form.json?from={0}&to={1}&text={2}";
                string url      = string.Format(_baseUrl, _inLang, _outLang, sentence);

                var tmpResult = MultillectWebRead.GetWebData(url, WebApi.WebReader.WebMethods.GET);

                var resp = JsonConvert.DeserializeObject <MultillectResponse.MultillectRoot>(tmpResult);

                result = resp.result.translations;
            }
            catch (Exception e)
            {
                Logger.WriteLog(Convert.ToString(e));
            }

            return(result);
        }
Beispiel #4
0
        public string Translate(string sentence, string inLang, string outLang)
        {
            sentence = sentence.Replace(":", " : ");
            string result = string.Empty;
            string url    = @"https://papago.naver.com/apis/n2mt/translate";

            if (_PapagoEncoder == null)
            {
                _PapagoEncoder = new PapagoEncoder(GlobalSettings.PapagoEncoderPath);
            }

            if (_PapagoEncoder.IsAvaliable)
            {
                try
                {
                    PapagoRequest papagoRequest = new PapagoRequest()
                    {
                        deviceId    = "",
                        dict        = false,
                        dictDisplay = 0,
                        honorific   = false,
                        instant     = false,
                        paging      = false,
                        source      = inLang,
                        target      = outLang,
                        text        = sentence
                    };

                    var reqv = _PapagoEncoder.EncodePapagoString(JsonConvert.SerializeObject(papagoRequest));

                    var tmpResponse = PapagoReader.GetWebData(url, WebApi.WebReader.WebMethods.POST, reqv);

                    PapagoResponse papagoResponse = JsonConvert.DeserializeObject <PapagoResponse>(tmpResponse);

                    result = papagoResponse.translatedText;
                }
                catch (Exception e)
                {
                    Logger.WriteLog(e);
                }
            }

            return(result);
        }