c# 3.0 - Translate one language to another in c# using google translator api -
See my code (see below) is to translate from one language to another, but it -1 in response ( Which is the default). Must show something in the first half, which looks like: { "responseData": { "translated text": "¿Cómo estás?"}, "Feedback Description": null, "response status": 200}
The second half format should be formatted and the items should be saved in a file.
public string translate (string original Angtekst, string Stringtutronslet, string Selaynej string to language) {/ have the string is not empty or void if (! String.IsNullOrOmptE (stringToTranslate)) {// per Google's terms, we can only translate the string of 5000 characters If (stringToTranslate.Length & lt; = 5000) {Const int bufSizeMax = 65536; Const int bufSizeMin = 8192; Try {// default, format? Is there a text, so no format is required to send? Key string Anuroduarai = "Http://ajaxkgoogleapiskcom/ajax/services/language/translate?v=lk0&q=" + Stringtronstret + "and Langpir =" + language + "% 7C" + toLanguage; // execute the request and receive the response stream HttpWebRequest request = (HttpWebRequest) WebRequest.Create (requestUri); HttpWebResponse response = (HttpWebResponse) request.GetResponse (); Stream response stream = response. Gateresonsstream (); // request int length = (int) response.ContentLength; Get the length of material received by; Int bufSize = bufSizeMin; If (length> buffs) {bufSize = length> BufSizeMax? BufSizeMax: Length; } // Allocation buffer and stringbilder response byte [] buf = new byte [bufSize]; Stringbirder sb = new stringbiller (buffsism); // Read the entire reaction ((length = Pratisadprkash. Read (buf, 0, buf.Length)) = 0) {sb.Append (encoding. UTF8.GetString (buf, 0, length)); } Strings translated = sb.Remove (0, 36) .toString (); TranslatedText = translatedText.Substring (0, translatedText.IndexOf ("\"}, "); {saveToFile (" translated text: "+ translated text);} translated translated;} catches (exception e) {original OriginalEngText; // Can not get translated}} and {{save] tofile ("basic angtext:" + original angtext);} Returns must be less than 5000 characters to translate original;}} and return {original intext} } // translating the string is empty}}}
Comments
Post a Comment