Open In App
Related Articles

How To Add Google Translate Button On Your Webpage?

Improve Article
Improve
Save Article
Save
Like Article
Like

Google Translate is a free multilingual machine translation service developed by Google, to translate text from one language into another. It offers a website interface, mobile apps for Android and iOS, and an API that helps developers build browser extensions and software applications. Google Translate supports over 100 languages at various levels. Follow the steps to add a google translate button on your website: Step 1: Start with a basic web page and add a “div” element. In the code below a “div” element with the id “google_translate_element” is created.  
Step 2: Add google translate api reference.  
Step 3: Add Javascript function..  
Example: 

html




<!DOCTYPE html>
<html lang="en-US">
 
<head>
    <title>
        How To Add Google Translate
        Button On Your Webpage ?
    </title>
</head>
 
<body>
    <p>Hello everyone!</p>
    <p>Welcome to GeeksforGeeks</p>
 
    <p>
        Translate this page in
        your preferred language:
    </p>
 
    <div id="google_translate_element"></div>
 
    <script type="text/javascript">
        function googleTranslateElementInit() {
            new google.translate.TranslateElement(
                {pageLanguage: 'en'},
                'google_translate_element'
            );
        }
    </script>
 
    <script type="text/javascript"
            src=
cb=googleTranslateElementInit">
    </script>
 
    <p>
        You can translate the content of this
        page by selecting a language in the
        select box.
    </p>
</body>
 
</html>


Output: Output after translating into Arabic:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 14 Oct, 2022
Like Article
Save Article
Similar Reads
Related Tutorials