March 12, 2011

English to Native language Transalator

This program is based on Console Application using C#.Net Framework 4.0. This program using Google Transaltion API and you get your transaltion API from Code.Google.com

Here's Code

static void Main(string[] args)
{
Console.WriteLine("Please write some thing here to be translate");

string text = Console.ReadLine();
string fromLanguage = "en"; //English
string toLanguage = "es"; // Spanish
string apiKey = ""; // Enter your APIKey here
string apiUrl = "https://www.googleapis.com/language/translate/v2?key={0}&source={1}&target={2}&q={3}";
string url = string.Format(apiUrl, apiKey, fromLanguage, toLanguage, text);

var translateLanguage = new Translate();
string returnData = translateLanguage.TranslateLanguage(url);
Console.WriteLine("Your translate sentence in spanish is: \n" + returnData);

Console.ReadLine();
}

Class Code

public class Translate
{
public string TranslateLanguage(string url)
{
string returnString = string.Empty;

try
{
WebRequest request = HttpWebRequest.Create(url);
request.Method = "GET";

using (WebResponse response = request.GetResponse())
{
using (var streamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
returnString = streamReader.ReadToEnd();
}
}
}
catch (Exception exception)
{
Console.Out.WriteLine(exception.Message);
}
return returnString;
}
}

1 comment:

  1. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.Chinese Interpreter BD and Chinese Interpreter Service in Bangladesh japanese interpreter Bd Chinese to bengali interpreting service in Dhaka

    ReplyDelete