public string Translate(string src, Language src_lang, Language dest_lang) { String result = null; BingService bs = new BingService(); SearchRequest sr = new SearchRequest(); sr.AppId = _apikey; sr.Sources = new SourceType[] { SourceType.Translation }; sr.Translation = new TranslationRequest(); sr.Translation.SourceLanguage = LangToString(src_lang); sr.Translation.TargetLanguage = LangToString(dest_lang); sr.Query = src; sr.Version = "2.2"; src = Unformat(src); SearchResponse response = bs.Search(sr); if (response != null) { if (response.Translation != null) { if (response.Translation.Results != null) { if (response.Translation.Results.Length > 0) { result = response.Translation.Results[0].TranslatedTerm; if (result.CompareTo(src) == 0) { result = null; } else if (result.Length == 0) { result = null; } } } } } if (result != null) { result = Format(result); } return result; }
/// <remarks/> public void SearchAsync(SearchRequest parameters, object userState) { if ((this.SearchOperationCompleted == null)) { this.SearchOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchOperationCompleted); } this.InvokeAsync("Search", new object[] { parameters}, this.SearchOperationCompleted, userState); }
/// <remarks/> public void SearchAsync(SearchRequest parameters) { this.SearchAsync(parameters, null); }
public SearchResponse Search(SearchRequest parameters) { object[] results = this.Invoke("Search", new object[] { parameters}); return ((SearchResponse)(results[0])); }