In this article, I am going to discuss the language converter in ASP.NET using the free Website Translator plugin of Google. This Google language converter plugin is a very powerful tool which will convert your website content to different languages within fractions of a second. This plugin supports more than 90 languages.

Here, I am explaining you the steps to integrate the language plugin in our website.
STEP 1: Open the following link to create an account in Google,
STEP 2: If you have any Google account, just login with that account, otherwise, create a new one.

STEP 3: After login, just click (Add to your website now) button. Here's the figure:

STEP 4: Add any URL as your website URL.
STEP 5: Click Next and choose the following setting as in the following image:

STEP 6: Click on getCode to get the code and copy paste the code where you want to show the Language converter on your website.

It will populate a dropdownlist with nearly 90+ languages in option.

Now, I am pasting it in my website as follows:

  1. <div>
  2. <div id="google_translate_element"></div>
  3. <script type="text/javascript">
  4. function googleTranslateElementInit() {
  5. new google.translate.TranslateElement
  6. ({ pageLanguage: 'en',
  7. layout: google.translate.TranslateElement.InlineLayout.SIMPLE },
  8. 'google_translate_element');
  9. }
  10. </script><script type="text/javascript"
  11. src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit">
  12. </script>
  13. </div>
Save the following code and run the website. It will populate a dropdown with the following language options.

Here are the languages,

STEP 7: Now create your own UI or content which you want to change using this Google plugin. I want to change my UI language using this plugin. Here is the UI design.


Now, here is the HTML code of my UI design.
  1. <div>
  2. <table>
  3. <tr>
  4. <td>
  5. Name:
  6. </td>
  7. <td>
  8. <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
  9. </td>
  10. </tr>
  11. <tr>
  12. <td>
  13. Registration No:
  14. </td>
  15. <td>
  16. <asp:TextBox ID="Textxt_regtBox1" runat="server"></asp:TextBox>
  17. </td>
  18. </tr>
  19. <tr>
  20. <td>
  21. Country:
  22. </td>
  23. <td>
  24. <asp:TextBox ID="txt_country" runat="server"></asp:TextBox>
  25. </td>
  26. </tr>
  27. </table>
  28. </div>
Add the following meta tag in the head section.
  1. <head runat="server">
  2. <title></title>
  3. <meta name="google-translate-customization"
  4. content="3280487709591956-dc3fc45d489f056a-g5378ebab0cbcd0a4-12"/>
  5. </head>
Now link your UI content div with google_translate_element as follows. Here, I have given the complete code.
  1. <%@ Page Language="C#" AutoEventWireup="true"
  2. CodeFile="Default.aspx.cs" Inherits="_Default" %>
  3. <!DOCTYPE html>
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title></title>
  7. <meta name="google-translate-customization"
  8. content="3280487709591956-dc3fc45d489f056a-g5378ebab0cbcd0a4-12"/>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <div>
  13. <div id="google_translate_element"></div>
  14. <script type="text/javascript">
  15. function googleTranslateElementInit() {
  16. new google.translate.TranslateElement({ pageLanguage: 'en',
  17. layout: google.translate.TranslateElement.InlineLayout.SIMPLE },
  18. 'google_translate_element');
  19. }
  20. </script><script type="text/javascript"
  21. src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit">
  22. </script>
  23. </div>
  24. <div id="google_translate_element">
  25. <table>
  26. <tr>
  27. <td>
  28. Name:
  29. </td>
  30. <td>
  31. <asp:TextBox ID="txt_name"
  32. runat="server"></asp:TextBox>
  33. </td>
  34. </tr>
  35. <tr>
  36. <td>
  37. Registration No:
  38. </td>
  39. <td>
  40. <asp:TextBox ID="Textxt_regtBox1"
  41. runat="server"></asp:TextBox>
  42. </td>
  43. </tr>
  44. <tr>
  45. <td>
  46. Country:
  47. </td>
  48. <td>
  49. <asp:TextBox ID="txt_country"
  50. runat="server"></asp:TextBox>
  51. </td>
  52. </tr>
  53. </table>
  54. </div>
  55. </form>
  56. </body>
  57. </html>
Now run the website and change to any language. You will get the result as follows:
So in this way, you can change the language of your website using the Google Translator Plugin.
Read more articles on ASP.NET: