Categories: PHP

how to add a Google Translate button on your website

Hii, Everyone Today i am going to tell you how to add a Google Translate button on your website.

Step 1:

  Add a <div> element with the id “google_translate_element”: inside  <body> tag

<div id=”google_translate_element”></div>

Step 2:

Add a Script tag in between <head></head>

<script type=”text/javascript” src=”//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit”></script>

 

Step 3:

  also add some javascript code in your webpages.

There are 3 types of button available for the Google Translate button.

 A.  Vertically

<script type=”text/javascript”>
                    function googleTranslateElementInit() {
                   new google.translate.TranslateElement({pageLanguage: ‘en’},                                ‘google_translate_element’);
                                 }
             </script>

 

B. Horizontal

 <script type=”text/javascript”>
                    function googleTranslateElementInit() {
                       new google.translate.TranslateElement({pageLanguage: ‘en’, layout:                              google.translate.TranslateElement.InlineLayout.HORIZONTAL}, ‘google_translate_element’);
               }
            </script>

 

 C.  Dropdown Menu, with no other text:

                  <script type=”text/javascript”>
                         function googleTranslateElementInit() {
                            new google.translate.TranslateElement({pageLanguage: ‘en’, layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, ‘google_translate_element’);
                                 }
                 </script>

 

And you are ready to translate the content of your page:

Basant Mallick

Basant

Recent Posts

How to Add Auto Increment to a Column in PostgreSQL ?

Learn how to efficiently set up auto-increment columns in PostgreSQL with this step-by-step guide. From…

5 hours ago

How to get the value of selected radio button using jQuery

Just use below code and modified according to your need. Note: this is very useful…

3 months ago

AWS

Steps: AWS puttyubuntu sudo su apt update apt install apache2 service apache2 start service apache2…

8 months ago