Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

C# Translator [using GOOGLE API]


  • Please log in to reply
13 replies to this topic

#13 Dedman


    CC Newcomer

  • Member
  • PipPip
  • 11 posts
  • Programming Language:Java, C++
  • Learning:Java, C++, C#, PHP, JavaScript, Others

Posted 19 December 2012 - 01:03 PM

Man that kinda stinks I was looking forward to making one of these.
  • 0

#14 mywolfrayet


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C#, PHP
  • Learning:C#, PHP

Posted 25 January 2013 - 04:31 AM


this thread is a full tutorial about making a Translator using Google's API to build a C# Windows Forms Applications that uses your internet connection and translate your text from google

What Do You Need ?

1- Google API , download it from the attachments
-the API I used , I downloaded it from CodePlex since code.google is forbidden in my Country :sleep: -

2- .NET framework 3.5

WHY 3.5 ? if you are using .NET 4.0 you need to get a newer API than this I used
ARE YOU USING Visual Studio 2010 ? so the Default is .NET 4.0
HOW TO MAKE IT 3.5 ? follow me in pics :confused: :

Go to Solution Explorer --> Right Click on the Project File --> Choose 3.5 client profile from the framework target
Posted Image

**First Step**
now open your Windows Forms project , Before Starting in Designing the form
let's add the API , google API is a dll library

adding it code be done from the Solution Explorer --> Right Click on References --> Add Reference
Posted Image

by Clicking OK , you should take attention that the GOOGLE namespace is now available
go to your FORM code and add

using Google.API.Translate;
Posted Image

**Second Step**
making the Form design :
see my design and you can make any changes you want
Posted Image

if you have any questions about ToolStrip menu or any GUI ask me ... but it's simple and easy

**Third Step : CODING**
first : let's fulfill the combo boxes with languages FROM and TO that google translator give us it using it's API

DOUBLE CLICK on the combo box will take you to the event "Click"
my combo box name is "combo_from"
type this code :
for (int i = 0; i < Google.API.Translate.Language.TranslatableCollection.Count(); i++)
and the same thing for the second combobox ...

second : translate METHOD that the translate button will call it

public string TranslateYourText(string text, string langFrom, string langTo)
string translated = "";
TranslateClient client = new TranslateClient("");
Language lang1 = Language.English;
Language lang2 = Language.Arabic;
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
if (ci.EnglishName == langFrom)
lang1 = ci.Name;
if (ci.EnglishName == langTo)
lang2 = ci.Name;
if (Autodetect == true)
string from;
translated = client.TranslateAndDetect(text, lang2.ToString(), out from);
foreach (string options in Language.GetEnums())
if (options == from)
CultureInfo ci = new CultureInfo(from);
combo_from.Text = ci.EnglishName;

translated = client.Translate(text, lang1, lang2, TranslateFormat.Text);
return translated;
MessageBox.Show(this, "Check Your Internet Connection","Try Again Please",MessageBoxButtons.OK,MessageBoxIcon.Error);
return translated;

now , you should know one thing , using (Display Parameter Info) and (Display Quick Info) is very important now since you don't know what's the behavior of Google Api

about the TranslateYourText method :
  • 3 parameters , text you want to translate , lang. from and lang. to
  • Creating an instance of TranslateClient
    TranslateClient client = new TranslateClient("");
  • Languages available written in English
anyhow , this method is one and only method and your translation is ready

Double Click on the Translate button and ...paste this

string translated = TranslateYourText(txt_from.Text, combo_from.Text, combo_to.Text);
txt_to.Text = translated;

if you have any questions , ask ..!

if you have any updates , the project is available for all code callers and every body make an update please write his name in the about

and thank you[ATTACH]4007[/ATTACH]

  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download