Image

How To Add Google Translate Button In Your Website?

How To Add Google Translate Button In Your Website?

Answer: Lets first know what is google translater Google Translate is a free multilingual machine translation service developed by Google.to translate website text from one language into another.

You can translate text, handwriting, photos, and speech in over 100 languages with the Google Translate app. Or you can use Translate on the web.

Steps

1)First, add div element in your webpage

<div id="google_translate_element"></div>

2)Second Add google translate API reference.

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

3)Add Javascript function.
<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

Complete Code

<!DOCTYPE html>
<html lang="en-US">
<body>

<h1>My Web Page</h1>

<p>Hello everybody!</p>

<p>Translate this page:</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="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

<p>You can translate the content of this page by selecting a language in the select box.</p>

</body>
</html>

Before Translation

before-google-translation

After Translation

after-google-translation

 

 

Categories: PHP Tags: #PHP 7,

Newsletter Subcribe

Receive updates and latest news direct from our team. Simply enter your email.