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 make dependent dropdown of state and district using cakephp2 form?

Creating dependent dropdowns in CakePHP 2 involves using AJAX to dynamically load data into the…

12 hours ago

How to make id as auto increment in postgrey SQL?

just add below code in column properties id Default input Method: 1nextval('form_submissions_id_seq'::regclass) Method: 2 Via…

15 hours ago

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…

1 month ago