Created
March 7, 2011 03:55
-
-
Save pmn/858043 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TranslateAPI | |
{ | |
private string TranslateURL { get; set; } | |
public TranslateAPI() | |
{ | |
var appConfig = ConfigurationManager.AppSettings; | |
var baseurl = appConfig["TranslateBaseURL"]; | |
var apiKey = appConfig["TranslateAPIKey"]; | |
TranslateURL = baseurl + "?key=" + apiKey; | |
} | |
public string Translate(string content, string fromLanguage, string toLanguage) | |
{ | |
// build up the url | |
var requestUrl = TranslateURL + "&q=" + HttpUtility.UrlEncode(content) + "&source=" + fromLanguage + "&target=" + toLanguage; | |
// connect to the url and download the result string | |
var translateClient = new WebClient(); | |
var result = translateClient.DownloadString(requestUrl); | |
// ship it back to the caller | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment