コード例 #1
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var uri = string.Format(configuration.ZarganTranslateUrl, HttpUtility.UrlEncode(translateRequest.CurrentText, Encoding.UTF8));

            var compositeMean = await new RestClient(uri)
            {
                Encoding = Encoding.UTF8
            }
            .ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader("Accept-Language", "en-US,en;q=0.8,tr;q=0.6")
                .AddHeader("Accept-Encoding", "gzip, deflate, sdch")
                .AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36")
                .AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content, translateRequest.FromLanguageExtension);

            return(new TranslateResult(true, mean));
        }
コード例 #2
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var parameter =
                $"sl=auto&text={Uri.EscapeUriString(translateRequest.CurrentText)}&tl={configuration.ToLanguageExtension}";

            var response = await new RestClient(configuration.SesliSozlukUrl)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecutePostTaskAsync(
                new RestRequest(Method.POST)
                .AddHeader("accept-language", "en-US,en;q=0.8,tr;q=0.6")
                .AddHeader("accept-encoding", "gzip, deflate")
                .AddHeader("content-type", "application/x-www-form-urlencoded")
                .AddHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36")
                .AddHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                .AddParameter("application/x-www-form-urlencoded", parameter, ParameterType.RequestBody));

            var meanOrganizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean          = await meanOrganizer.OrganizeMean(response.Content);

            return(new TranslateResult(true, mean));
        }
コード例 #3
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var requestObject = new
            {
                from = configuration.FromLanguage.ToLower(),
                to   = configuration.ToLanguage.ToLower(),
                text = translateRequest.CurrentText
            };

            var response = await new RestClient(configuration.BingTranslatorUrl)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecutePostTaskAsync(new RestRequest(Method.POST)
                                   .AddHeader("content-type", "application/json;Charset=UTF-8")
                                   .AddParameter("application/json;Charset=UTF-8",
                                                 JsonConvert.SerializeObject(requestObject),
                                                 ParameterType.RequestBody));

            var meanOrganizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean          = await meanOrganizer.OrganizeMean(response.Content);

            return(new TranslateResult(true, mean));
        }
コード例 #4
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var address = new Uri(string.Format(configuration.YandexUrl +
                                                $"key={configuration.ApiKey}&lang={translateRequest.FromLanguageExtension}-{configuration.ToLanguageExtension}&text={Uri.EscapeUriString(translateRequest.CurrentText)}"));

            var compositeMean = await new RestClient(address).ExecutePostTaskAsync(new RestRequest(Method.POST));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content);

            return(new TranslateResult(true, mean));
        }
コード例 #5
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var uri = new Uri(configuration.TurengUrl + translateRequest.CurrentText);

            var compositeMean = await new RestClient(uri)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36")
                .AddHeader("Accept-Language", "en-US,en;q=0.8,tr;q=0.6"));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content, translateRequest.FromLanguageExtension);

            return(new TranslateResult(true, mean));
        }