Given below is a simple HTML page, which has scripts for Google Translator-
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5. <title>Google Translator - Basic Translation</title>
  6. <style>
  7. body {
  8. top: 0 !important;
  9. }
  10. .goog-te-banner-frame {
  11. display: none;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="google_translate_element">
  17. </div>
  18. <script type="text/javascript">
  19. function googleTranslateElementInit() {
  20. new google.translate.TranslateElement({
  21. pageLanguage: 'en',
  22. layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  23. }, 'google_translate_element');
  24. }
  25. </script>
  26. <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
  27. <br />
  28. <div>
  29. Hi, Good morning! This is a simple text for testing the Google's translator.
  30. </div>
  31. </body>
  32. </html>
While running page, shown above, in the Browser, Google automatically creates a dropdown structure at the top of the page, inside div provided by us with ID "google_translate_element".


We can reposition this div to our desired position, using css.

The default language was set as English. While clicking the dropdown, we will get a list of languages, available for the translation.

Clicking on any of the language will make a complete Webpage translated to that particular language. Here, the Webpage is translated to Spanish.


For more details of implementing a translator in your Website, please visit this link. Hope, this will be helpful for someone out there.

1 Comment

Join the conversation! Your thoughts help the community grow.

  • I want to implement Hindi typing in my website, i.e. implement a form that will allow typing in Hindi. How do I do that?