Jump to content




Recent Status Updates

  • Photo
      15 Nov
    duzamucha

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
Photo
- - - - -

C# Translator [using GOOGLE API]

combobox

  • Please log in to reply
13 replies to this topic

#1 Professor Green

Professor Green

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 14 July 2011 - 09:05 AM

Hello

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

LET'S START :
**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++)
            {
                combo_from.Items.Add(Google.API.Translate.Language.TranslatableCollection.ElementAt(i).ToString());
            }
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 = "";
            Console.WriteLine(text);
            try
            {
                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;
                        }

                    }
                }
                else
                {
                    translated = client.Translate(text, lang1, lang2, TranslateFormat.Text);
                    Console.WriteLine(translated);
                }
                return translated;
            }
            catch
            {
                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]

Attached Files


Edited by Professor Green, 14 July 2011 - 02:08 PM.
add the project src code

  • 3

#2 sam_coder

sam_coder

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 380 posts

Posted 14 July 2011 - 10:46 AM

it's funny that code.google is blocked, but google services are not. =)

Fun tutorial! great work! +rep
  • 0

#3 Professor Green

Professor Green

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 14 July 2011 - 12:34 PM

sam_coder , thank u

am gonna show you how does code.google appear here !!!
that's what I call real fun ;p
and all google services works perfect here , maps , translator ... everything
but no access for codes
123132123.png
  • 0

#4 sam_coder

sam_coder

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 380 posts

Posted 15 July 2011 - 08:29 AM

wow, that's weird. Not that I understand the specific politics surrounding that, or the laws in your area, but I betcha Tor could get you around that.

Tor Project: Anonymity Online

I know that at times when I've used this, which is perfectly legal where I am, I've hit Google's site, and it's redirected me to Google Russia or whatever.

Anyways, that's well beyond the scope of this tutorial, so I'll be quiet. =)
  • 0

#5 mak_code

mak_code

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 31 March 2012 - 12:25 AM

Hi all,

I run the above code,but unfortunally i got below error
[response status:403]Please use Translate v2. See Google Translate API v2 - Google Code

Code:
string input="Abdulrahman";
string Domain = "Domainname";
string username = "usename";
string password = "password";
string ur = "http://translate.google.com.sa/?hl=en&tab=wT#";
HttpWebRequest webRequest1 = WebRequest.Create(ur) as HttpWebRequest;
System.Net.NetworkCredential netcredt = new System.Net.NetworkCredential(username, password, Domain);
System.Net.WebResponse response = webRequest1.GetResponse();
TranslateClient cient = new TranslateClient(ur);
string trtad = cient.Translate(input, "en", "ar");

Can anyone tell me wts the problem..?

Thanks
Mak.
  • 0

#6 adnan

adnan

    CC Lurker

  • New Member
  • Pip
  • 2 posts

Posted 18 April 2012 - 11:05 PM

i m getting runtime error "Check Your Internet Connection"..
  • 1

#7 adnan

adnan

    CC Lurker

  • New Member
  • Pip
  • 2 posts

Posted 19 April 2012 - 01:03 AM

is it required to have API key for this software to work ..plz let me know its urgent...
  • 0

#8 sathikali

sathikali

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Learning:C++, C#, (Visual) Basic, JavaScript, Visual Basic .NET, VBScript

Posted 19 July 2012 - 02:23 AM

i am getting "check your internet connection" error please help me
  • 1

#9 mohax

mohax

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 31 July 2012 - 06:09 AM

"check your internet connection" error
  • 0

#10 NeerajAwasthi

NeerajAwasthi

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C#

Posted 25 September 2012 - 01:36 AM

hello i am getting error
if (Autodetect == true)
Autodetect does not exist in current context.
please help me.....
  • 0

#11 zbojnik

zbojnik

    CC Newcomer

  • Member
  • PipPip
  • 22 posts
  • Programming Language:C#
  • Learning:C#

Posted 12 November 2012 - 07:52 AM

Does this tutorial still work? I think I read somewhere that google translator API does not work anymore. Is this true?
  • 0

#12 Zouhir

Zouhir

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:C
  • Learning:C

Posted 12 November 2012 - 09:26 AM

hi all .. Google translator API is now paid API and old APIs are not working anymore.. this tutorials was working and the code is valid but GOOGLE is not supporting this version of API an the new is paid

hi all .. Google translator API is now paid API and old APIs are not working anymore.. this tutorials was working and the code is valid but GOOGLE is not supporting this version of API an the new is paid
  • 0





Powered by binpress