Using the Google Translator in Web API


This article explains how to add the Google Translator to a Web API application.

Google Translator

The Google Translator translates the search Query to the language you want. Google Translator is a free statistical multilingual machine translation service that is provided by Google. It translates written text from one language to another.

Now you can see the process of using the Google Translator in a Web API application as in the following:

  1. First we create a Google Account.
  2. To integrate the Google Translator, login with your Gmail id from this link:

  1. Click on "Sign in".

Sign in with your Gmail id.

  1. Then login with your id. Open a window.


  1. Click on the tab "Add to your website now" .

Type your website URL in the "website URL" TextBox.


Website URL:  in this block you write your website URL.

Website language: It defines the default language for your website.

Click on the "Next" button.

  1. Open a window in which you select "translation language", "display mode" and click on "Get Code" button.


Translation Languages: here two options are available as in the following:

  • All language: If we select all languages then it shows all the languages that are used in the Google Translator.
  • Specific languages: If you select this option then you choose a specific language.

Display mode: This mode defines the list of languages in a different mode.

Now click on the "Get Code" button.


  1. Create a Web API application as in the following:
  • Start Visual Studio 2012.
  • From Start window select "New Project".
  • From the new project window select "Installed" -> "Visual C#" -> "Web".
  • Select "ASP.NET MVC4 Web Application" and click on the "OK" button.


  • From the "MVC4 Project" window select "Web API".


  • Click the "OK" button.
  1. For copying the code you need the "index.cshtml" file. This file exists:
  • In the "Solution Explorer".
  • Expand "Home" folder.
  • Select the "index.cshtml" file and add the code.


Copy the Meta tag content and paste it in the "<head>" tag.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">






       <meta name="google-translate-customization" content="3280487709591956-dc3fc45d489f056a-g5378ebab0cbcd0a4-12"/>



Now copy the block of code and paste it into the "<body>" tag.


<div id="google_translate_element">

    Welcome to! MSDN Site.

</div><script type="text/javascript">

          function googleTranslateElementInit()


            new google.translate.TranslateElement({ pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element');



    <script type="text/javascript" src="//">






  1. Now execute the application:


Click on the Dropdown list:


Select any language. Here the output looks like this:


Up Next
    Ebook Download
    View all
    View all