public async Task <TranslationViewModel> TranslatePartial(String tekstZaPreveduvanje) { //Da se napravi detectLanguage(tekstZaPreveduvanje) TranslationViewModel result = await MacedonianCroatianEnglishGermanTranslation.DeEnCroMk(tekstZaPreveduvanje, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); return(result); }
public async Task <IActionResult> Index(IndexViewViewModel indexViewViewModel) { if (!ModelState.IsValid) { return(View(new IndexViewViewModel(new TranslationViewModel(), new SelectLanguageTranslationListViewModel()))); } //_logger.LogInformation("_googleReCaptcha.Value.SecretKey"); //_logger.LogInformation(_googleReCaptcha.Value.SecretKey); //_logger.LogInformation("_googleReCaptchaV3.Value.v3_secret");_ //_logger.LogInformation(_googleReCaptchaV3.Value.v3_secret); /* * * var data = await verifyReCaptcha("v2", indexViewViewModel.GoogleReCaptchaResponse); * //_logger.LogInformation("data.IsHttpResponseOk" + data.IsHttpResponseOk.ToString()); * //_logger.LogInformation("indexViewViewModel.GoogleReCaptchaResponse" + indexViewViewModel.GoogleReCaptchaResponse); * //_logger.LogInformation("data.reCaptchaVerifyResponse[\"success\"].ToString().ToLower()" + data.reCaptchaVerifyResponse["success"].ToString().ToLower()); * //_logger.LogInformation("data.reCaptchaVerifyResponse[\"hostname\"].ToString()" + data.reCaptchaVerifyResponse["hostname"].ToString()); * * if (data.IsHttpResponseOk && data.reCaptchaVerifyResponse["success"].ToString().ToLower().Equals("true") && (data.reCaptchaVerifyResponse["hostname"].ToString().Equals("clean-yew-270306.appspot.com"))) * //|| data.reCaptchaVerifyResponse["hostname"].ToString().Equals("localhost"))) * {*/ //_logger.LogInformation("Verified ReCaptcha"); // Write the log entry. //_logger.LogInformation("Post Index Method"); // Add a handler to trace outgoing requests and to propagate the trace header. //indexViewViewModel.translationViewModel.TekstZaPreveduvanje = HttpUtility.HtmlEncode(indexViewViewModel.translationViewModel.TekstZaPreveduvanje); if (indexViewViewModel.selectLanguageTranslationListViewModel.SelectedPrevod.Equals("MkDe") && !String.IsNullOrEmpty(indexViewViewModel.translationViewModel.TekstZaPreveduvanje)) { //_logger.LogInformation("if MkDe"); //_logger.LogInformation("if MkDe : indexViewViewModel.translationViewModel.TekstZaPreveduvanje = " + indexViewViewModel.translationViewModel.TekstZaPreveduvanje); indexViewViewModel.translationViewModel.Makedonski = indexViewViewModel.translationViewModel.TekstZaPreveduvanje; TranslationViewModel result = await MacedonianCroatianEnglishGermanTranslation.MkCroEnDe(indexViewViewModel.translationViewModel.Makedonski, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); indexViewViewModel.translationViewModel = result; //indexViewViewModel.translationViewModel.Makedonski = HttpUtility.HtmlDecode(indexViewViewModel.translationViewModel.Makedonski); return(View("Index", indexViewViewModel)); } else if (indexViewViewModel.selectLanguageTranslationListViewModel.SelectedPrevod.Equals("DeMk") && !String.IsNullOrEmpty(indexViewViewModel.translationViewModel.TekstZaPreveduvanje)) { //_logger.LogInformation("else if DeMk"); //_logger.LogInformation("else if DeMk : indexViewViewModel.translationViewModel.TekstZaPreveduvanje = " + indexViewViewModel.translationViewModel.TekstZaPreveduvanje); indexViewViewModel.translationViewModel.Germanski = indexViewViewModel.translationViewModel.TekstZaPreveduvanje; TranslationViewModel result = await MacedonianCroatianEnglishGermanTranslation.DeEnCroMk(indexViewViewModel.translationViewModel.Germanski, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); indexViewViewModel.translationViewModel = result; //indexViewViewModel.translationViewModel.Germanski = HttpUtility.HtmlDecode(indexViewViewModel.translationViewModel.Germanski); return(View("Index", indexViewViewModel)); } /*} * else * { * ViewData["error"] = "Invalid ReCaptcha"; * }*/ return(View(new IndexViewViewModel(new TranslationViewModel(), new SelectLanguageTranslationListViewModel()))); }
public async Task <TranslationViewModel> WordExamplesTextTranslate(String text) { TranslationViewModel translatedText = await MacedonianCroatianEnglishGermanTranslation.DeEnCroMk(text, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); return(translatedText); }
public async Task <IActionResult> WordExamples(WordExamplesViewModel wordExamplesViewModel, int?pageNumber) { if (!ModelState.IsValid) { return(null); } int pageSize = 5; String Word = wordExamplesViewModel.Word; var SessionWord = HttpContext.Session.GetString(_SessionWord); if (!String.IsNullOrEmpty(SessionWord)) { if (SessionWord.Equals(wordExamplesViewModel.Word)) { //Вчитај примери текст поле за вчитување преводи //Ako requestot e od istiot korisni i veke e prevedeno zborceto var SessionSenses = HttpContext.Session.GetObjectFromJson <List <TranslationViewModel> >(_SessionSenses); var SessionTranslatedSenses = HttpContext.Session.GetObjectFromJson <List <TranslationViewModel> >(_SessionTranslatedSenses); var SessionTranslatedSensesSumary = HttpContext.Session.GetObjectFromJson <List <TranslationViewModel> >(_SessionTranslatedSensesSumary); PaginatedList <TranslationViewModel> sessionPaginatedList = PaginatedList <TranslationViewModel> .Create( SessionTranslatedSensesSumary, pageNumber ?? 1, pageSize); if (SessionSenses != null && SessionSenses.Count() > 0 && sessionPaginatedList.Any(m => m.TekstZaPreveduvanje == wordExamplesViewModel.Word && m.Hrvatski == null && m.Angliski == null)) { wordExamplesViewModel.TranslaatedTextToReturn = PaginatedList <TranslationViewModel> .Create( SessionSenses, pageNumber ?? 1, pageSize); List <TranslationViewModel> Result = new List <TranslationViewModel>(); TranslationViewModel result = new TranslationViewModel(); foreach (var tekst in wordExamplesViewModel.TranslaatedTextToReturn) { if (wordExamplesViewModel.selectLanguageTranslationListViewModel.SelectedPrevod.Equals("MkDe") && tekst.Hrvatski == null && tekst.Angliski == null) { result = await MacedonianCroatianEnglishGermanTranslation.MkCroEnDe(tekst.Makedonski, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); result.TekstZaPreveduvanje = Word; SessionTranslatedSenses.Add(tekst); Result.Add(result); } else if (wordExamplesViewModel.selectLanguageTranslationListViewModel.SelectedPrevod.Equals("DeMk") && tekst.Hrvatski == null && tekst.Angliski == null) { result = await MacedonianCroatianEnglishGermanTranslation.DeEnCroMk(tekst.Germanski, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); result.TekstZaPreveduvanje = Word; SessionTranslatedSenses.Add(result); Result.Add(result); } } //wordExamplesViewModel.TranslaatedTextToReturn.Add(result); for (int i = 0; i < Result.Count; i++) { for (int j = 0; j < SessionSenses.Count; j++) { if (SessionSenses[j].Germanski == Result[i].Germanski) { SessionTranslatedSensesSumary[j].TekstZaPreveduvanje = Result[i].TekstZaPreveduvanje; SessionTranslatedSensesSumary[j].Makedonski = Result[i].Makedonski; SessionTranslatedSensesSumary[j].Hrvatski = Result[i].Hrvatski; SessionTranslatedSensesSumary[j].Angliski = Result[i].Angliski; SessionTranslatedSensesSumary[j].Germanski = Result[i].Germanski; SessionSenses[j].TekstZaPreveduvanje = Result[i].TekstZaPreveduvanje; SessionSenses[j].Makedonski = Result[i].Makedonski; SessionSenses[j].Hrvatski = Result[i].Hrvatski; SessionSenses[j].Angliski = Result[i].Angliski; SessionSenses[j].Germanski = Result[i].Germanski; } } } wordExamplesViewModel.TranslaatedTextToReturn = PaginatedList <TranslationViewModel> .Create( SessionTranslatedSensesSumary, pageNumber ?? 1, pageSize); HttpContext.Session.SetObjectAsJson(_SessionTranslatedSenses, SessionTranslatedSenses); HttpContext.Session.SetObjectAsJson(_SessionTranslatedSensesSumary, SessionTranslatedSensesSumary); return(PartialView("_sensesPartialView", wordExamplesViewModel)); } else { wordExamplesViewModel.TranslaatedTextToReturn = PaginatedList <TranslationViewModel> .Create( SessionTranslatedSensesSumary, pageNumber ?? 1, pageSize); return(PartialView("_sensesPartialView", wordExamplesViewModel)); } } } if (String.IsNullOrEmpty(wordExamplesViewModel.Word)) { return(null); } String UserWordToTranslate = wordExamplesViewModel.Word; if (wordExamplesViewModel.selectLanguageTranslationListViewModel.SelectedPrevod.Equals("MkDe")) { TranslationViewModel result = await MacedonianCroatianEnglishGermanTranslation.MkCroEnDe(wordExamplesViewModel.Word, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); wordExamplesViewModel.Word = result.Germanski; } wordExamplesViewModel.Word = await lemmas(wordExamplesViewModel.Word.ToLower()); HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("https://od-api.oxforddictionaries.com/api/v2/translations/de/en/" + HttpUtility.UrlEncode(wordExamplesViewModel.Word)); Dictionary <string, string> queryString = new Dictionary <string, string>(); queryString = new Dictionary <string, string>() { { "strictMatch", "true" }, { "fields", "examples" } }; var requestQueryString = QueryHelpers.AddQueryString("", queryString); var request = new HttpRequestMessage(HttpMethod.Get, requestQueryString); request.Headers.Add("Accept", "application/json"); request.Headers.Add("app_id", _oxfordDictionariesApi.Value.app_id); request.Headers.Add("app_key", _oxfordDictionariesApi.Value.app_key); var httpResponse = await httpClient.SendAsync(request); WordExamplesViewModel wordExamplesViewModelToReturn = wordExamplesViewModel; wordExamplesViewModelToReturn.Senses = new List <TranslationViewModel>(); JObject data = new JObject(); if (httpResponse.StatusCode == HttpStatusCode.OK) { data = await getRequestJson(httpResponse); } else if (httpResponse.StatusCode == HttpStatusCode.NotFound) { return(null); } //return new JsonResult(data["results"].Children()["lexicalEntries"].Children()["entries"].Children()); foreach (var results in data["results"]) { foreach (var lexicalEntries in results.Value <JToken>("lexicalEntries")) { foreach (var entries in lexicalEntries.Value <JToken>("entries")) { foreach (var senses in entries.Value <JToken>("senses")) { foreach (var text in senses.Value <JToken>("examples")) { TranslationViewModel translationViewModel = new TranslationViewModel(); translationViewModel.Germanski = text.Value <String>("text"); translationViewModel.TekstZaPreveduvanje = Word; wordExamplesViewModelToReturn.Senses.Add(translationViewModel); } } } } } PaginatedList <TranslationViewModel> tempPaginatedList = PaginatedList <TranslationViewModel> .Create( wordExamplesViewModelToReturn.Senses, pageNumber ?? 1, pageSize); List <TranslationViewModel> tempTranslationViewModel = new List <TranslationViewModel>(); //prv pat zbor foreach (var tekst in tempPaginatedList) { TranslationViewModel result = await MacedonianCroatianEnglishGermanTranslation.DeEnCroMk(tekst.Germanski, _googleCloudPlatformProjectName.Value.ProjectName, _logger, _googleTranslateApiCredentials); result.TekstZaPreveduvanje = Word; tempTranslationViewModel.Add(result); } for (int i = 0; i < tempPaginatedList.Count; i++) { for (int j = 0; j < tempTranslationViewModel.Count; j++) { if (tempPaginatedList[i].Germanski == tempTranslationViewModel[j].Germanski) { tempPaginatedList[j].Makedonski = tempTranslationViewModel[i].Makedonski; tempPaginatedList[j].Hrvatski = tempTranslationViewModel[i].Hrvatski; tempPaginatedList[j].Angliski = tempTranslationViewModel[i].Angliski; tempPaginatedList[j].Germanski = tempTranslationViewModel[i].Germanski; } } } wordExamplesViewModelToReturn.TranslaatedTextToReturn = tempPaginatedList; List <TranslationViewModel> SessinTranslatedSensesSumary = wordExamplesViewModelToReturn.Senses; for (int i = 0; i < SessinTranslatedSensesSumary.Count; i++) { for (int j = 0; j < wordExamplesViewModelToReturn.TranslaatedTextToReturn.Count; j++) { if (wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Germanski == SessinTranslatedSensesSumary[i].Germanski && wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Hrvatski != null && wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Angliski != null) { SessinTranslatedSensesSumary[i].Makedonski = wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Makedonski; SessinTranslatedSensesSumary[i].Hrvatski = wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Hrvatski; SessinTranslatedSensesSumary[i].Angliski = wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Angliski; SessinTranslatedSensesSumary[i].Germanski = wordExamplesViewModelToReturn.TranslaatedTextToReturn[j].Germanski; } } } HttpContext.Session.SetObjectAsJson(_SessionSenses, wordExamplesViewModelToReturn.Senses); HttpContext.Session.SetObjectAsJson(_SessionTranslatedSenses, wordExamplesViewModelToReturn.TranslaatedTextToReturn); HttpContext.Session.SetObjectAsJson(_SessionTranslatedSensesSumary, SessinTranslatedSensesSumary); HttpContext.Session.SetString(_SessionWord, UserWordToTranslate); //return wordExamplesViewModelToReturn; return(PartialView("_sensesPartialView", wordExamplesViewModelToReturn)); }