public void BaiduDetect() { string detected = BaiduTranslateService.Detect("Hello"); Assert.AreEqual("en", detected); }
public void BaiduTranslate() { string translated = BaiduTranslateService.Translate("Hello", "ru"); Assert.AreEqual("привет", translated); }
public static List <TranslatorTextList> BaiduTranslatorTextLists(EntityModel entity) { List <TranslatorTextList> list = new List <TranslatorTextList>(); TranslatorTextList translatorTextList = new TranslatorTextList { CultureDisplayName = "中文", CultureSortName = "zh-Hans", TransTestList = new List <KeyValuePair <string, string> >() }; foreach (EntityFieldModel entityFieldModel in entity.Properties) { if (entityFieldModel.EditChecked || entityFieldModel.ListChecked) { if (entityFieldModel.FieldTypeStr == "string") { translatorTextList.TransTestList.Add(new KeyValuePair <string, string>(entityFieldModel.FieldName, entityFieldModel.FieldDisplayName)); translatorTextList.TransTestList.Add(new KeyValuePair <string, string>(entity.Name + entityFieldModel.FieldName, "请输入" + entityFieldModel.FieldDisplayName)); } else { translatorTextList.TransTestList.Add(new KeyValuePair <string, string>(entityFieldModel.FieldName, entityFieldModel.FieldDisplayName)); } } } list.Add(translatorTextList); TranslatorTextList translatorTextList2 = new TranslatorTextList { CultureSortName = "zh-Hant", CultureDisplayName = "繁体中文", TransTestList = new List <KeyValuePair <string, string> >() }; TranslatorTextList translatorTextList3 = new TranslatorTextList { CultureSortName = "viet", CultureDisplayName = "越南文", TransTestList = new List <KeyValuePair <string, string> >() }; TranslatorTextList translatorTextList4 = new TranslatorTextList { CultureSortName = "en", CultureDisplayName = "英语", TransTestList = new List <KeyValuePair <string, string> >() }; foreach (KeyValuePair <string, string> keyValuePair in translatorTextList.TransTestList) { TransRoot translate = BaiduTranslateService.GetTranslate(keyValuePair.Value, BaiduTrranslateEnum.auto, BaiduTrranslateEnum.cht); if (translate == null) { break; } string dst = translate.trans_result[0].dst; translatorTextList2.TransTestList.Add(new KeyValuePair <string, string>(keyValuePair.Key, dst)); string dst2 = BaiduTranslateService.GetTranslate(keyValuePair.Value, BaiduTrranslateEnum.auto, BaiduTrranslateEnum.vie).trans_result[0].dst; translatorTextList3.TransTestList.Add(new KeyValuePair <string, string>(keyValuePair.Key, dst2)); string dst3 = BaiduTranslateService.GetTranslate(keyValuePair.Value, BaiduTrranslateEnum.auto, BaiduTrranslateEnum.en).trans_result[0].dst; translatorTextList4.TransTestList.Add(new KeyValuePair <string, string>(keyValuePair.Key, dst3)); } list.Add(translatorTextList2); list.Add(translatorTextList3); list.Add(translatorTextList4); return(list); }