public string TranslateText(string input, string twoLetterIsolanguageCode)
{
if (CheckForInternetConnection())
{
string url = String.Format
("https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}",
"en",
twoLetterIsolanguageCode,
Uri.EscapeUriString(input));
HttpClient httpClient = new HttpClient();
var result = httpClient.GetStringAsync(url).Result;
var jsonData = new JavaScriptSerializer().Deserialize<List<dynamic>>(result);
var translationItems = jsonData[0];
string translation = "";
foreach (object item in translationItems)
{
IEnumerable? translationLineObject = item as IEnumerable;
IEnumerator translationLineString = translationLineObject.GetEnumerator();
translationLineString.MoveNext();
translation += string.Format(" {0}", Convert.ToString(translationLineString.Current));
}
if (translation.Length > 1) { translation = translation.Substring(1); };
return translation;
}
else
{
return input;
}
}
public string TranslateText(string input, string twoLetterIsolanguageCode)
{
if (CheckForInternetConnection())
{
string url = String.Format
("https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}",
"en",
twoLetterIsolanguageCode,
Uri.EscapeUriString(input));
HttpClient httpClient = new HttpClient();
var result = httpClient.GetStringAsync(url).Result;
var jsonData = new JavaScriptSerializer().Deserialize<List<dynamic>>(result);
var translationItems = jsonData[0];
string translation = "";
foreach (object item in translationItems)
{
IEnumerable? translationLineObject = item as IEnumerable;
IEnumerator translationLineString = translationLineObject.GetEnumerator();
translationLineString.MoveNext();
translation += string.Format(" {0}", Convert.ToString(translationLineString.Current));
}
if (translation.Length > 1) { translation = translation.Substring(1); };
return translation;
}
else
{
return input;
}
}