public async void getTranslation() { string source_lang = getLanguageId(SelectedInput); string target_lang = getLanguageId(SelectedOutput); var service = new DictionaryService(); var uri = "/api/v1/entries/" + source_lang + "/" + Word + "/translations=" + target_lang; if (SelectedInput == null || SelectedOutput == null) { DependencyService.Get <IMessage>().LongAlert("Please select language!"); } else { TransResult = await service.GetTranslationsAsync(uri); if (TransResult != null) { setTranslationValues(); } else { TranslationEntry.Clear(); } } }
public void setTranslationValues() { TranslationEntry.Clear(); foreach (var k in TransResult.results) { if (k.lexicalEntries != null) { foreach (var i in k.lexicalEntries) { var trans_item = new TranslateEntry(); trans_item.Type = i.lexicalCategory; trans_item.Examples = "Examples: \n\n"; trans_item.Translations = "Translations: \n\n"; if (i.entries != null) { foreach (var j in i.entries) { if (j.senses != null) { foreach (var y in j.senses) { if (y.translations != null) { foreach (var x in y.translations) { if (!trans_item.Translations.Contains(x.text)) { trans_item.Translations += x.text + "\n"; } } } if (y.examples != null) { foreach (var example in y.examples) { if (example.translations != null) { trans_item.Examples += example.text + "\n" + example.translations.ElementAt(0).text + "\n\n"; } } } if (y.subsenses != null) { foreach (var x in y.subsenses) { if (x.translations != null) { foreach (var trans in x.translations) { if (!trans_item.Translations.Contains(trans.text)) { trans_item.Translations += trans.text + "\n"; } } } if (x.examples != null) { foreach (var example in x.examples) { if (example.translations != null) { trans_item.Examples += example.text + "\n" + example.translations.ElementAt(0).text + "\n\n"; } } } } } } } } } TranslationEntry.Add(trans_item); } } } }