public override WordOfDictionary TranslateWord(string word,Language SourceLang,Language TargetLang) { WordOfDictionary WordOfDictionary = new WordOfDictionary(); LinguaLeoAPI.TranslateAPIResponse resp = api.TranslateWord_withoutlogin(word); WordOfDictionary.word_of_dictionary = word; WordOfDictionary.outer_id = resp.word_id; WordOfDictionary.transcription = resp.transcription; WordOfDictionary.sound_url = resp.sound_url; WordOfDictionary.pictures_url = resp.pic_url; foreach(var elm in resp.translate) { TranslationOfWord tr = new TranslationOfWord(); tr.external_id = elm.id; tr.Translation = elm.value; tr.Votes = elm.votes; //tr.picture_url = elm.pic_url; tr.SetPictureUrl(elm.pic_url); WordOfDictionary.translations.Add(tr); } if (WordOfDictionary.translations.Count > 0) { WordOfDictionary.translation_as_string = WordOfDictionary.translations.OrderByDescending(x => x.Votes).First().Translation; WordOfDictionary.translations[0].Selected = true; WordOfDictionary.translations[0].Index_of_selection = 1; } return WordOfDictionary; }
public override string TranslateText(string text, Language SourceLang, Language TargetLang) { if (string.IsNullOrEmpty(text)) return ""; LanguageOfService LS_SourceLang = GetLanguageServiceByLanguage(SourceLang); LanguageOfService LS_TargetLang = GetLanguageServiceByLanguage(TargetLang); //string lang = "en-ru"; string lang = LS_TargetLang.Code + "-" + LS_SourceLang.Code; /* key=<API-ключ> & text=<переводимый текст> & lang=<направление перевода> & [format=<формат текста>] & [options=<опции перевода>] */ string SubText = text.Replace("\r\n", " -.- "); string URL = "https://translate.yandex.net/api/v1.5/tr/translate" + "?key=" + Key + "&lang=" + lang + "&text=" + SubText; WebRequest request = WebRequest.Create(URL); WebResponse response = request.GetResponseAsync().Result; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { var fetchedXml = sr.ReadToEnd(); /* XmlDocument d = new XmlDocument(); d.LoadXml(fetchedXml); XmlNodeList textNodes = d.GetElementsByTagName("text"); return textNodes[0].InnerText.Replace(" -.- ", "\r\n"); */ XmlReader reader = XmlReader.Create(sr); reader.MoveToContent(); reader.ReadToDescendant("text"); string txt = reader.ReadElementContentAsString(); return txt.Replace(" -.- ", "\r\n"); } }
public override string ContextURL(string word, Language SourceLang, Language TargetLang) { string url = "http://www.merriam-webster.com/dictionary/"+word; return url; }
public override string ContextURL(string word, Language SourceLang, Language TargetLang) { LanguageOfService SourceLang_ = Languages.FirstOrDefault(x => x.SourceLanguage_id == SourceLang.id); if(SourceLang_ == null) { SystemMessage.Show("Can't found language "+SourceLang+" for service "+this); return ""; } LanguageOfService TargetLang_ = Languages.FirstOrDefault(x => x.SourceLanguage_id == TargetLang.id); if(TargetLang_ == null) { SystemMessage.Show("Can't found language "+TargetLang_+" for service "+this); return ""; } string url = @"https://translate.google.com/#"+SourceLang_.Code+@"/"+TargetLang_.Code+@"/"+word; return url; }
public void LoadLanguagesIntoMainLanguages() { List<GoogleTranslationService.languages> lst = GetLanguageList(); foreach(var lang in lst) { Language lng; lng = EFDbContext.Context.FirstOrDefault<Language>("Code = '"+lang.language+"'"); if(lng == null) { lng = new Language { Code = lang.language}; EFDbContext.Context.AddNewItemToDBContext(lng); } lng.EngName = lang.name; } EFDbContext.SaveChgs(); }
public override string ContextURL(string word, Language SourceLang, Language TargetLang) { string url = "http://www.macmillandictionary.com/us/dictionary/american/"+word; return url; }