http://phpcoder.tech/how-to-integrate-google-translate-on-website/

Integrate Google Translate on website is a great way to provide your content all over the world with great content. But as a developer, we have to get that knowledge about how Google Translate works.

How Google Translate works

If we think that Google has a huge database of words then the answer is “No”.

Generally, Google Translate working is based on “SMT” (statistical machine translation).

  • Means Google gets the data from the user entries and they used to find those words parallel for matching.
  • They take input letters and produce an output sequence of those letters.

Done with a small explanation about how Google Translate works!

Now we start How to Integrate Google Translate on website step by step,

  • First, we create a <div> with id="google_translate_element"
<!DOCTYPE html>
<html>
<body>
<h1>Integrate Google Translate on website</h1>
<div id="google_translate_element"></div>
</body>
<html>
//API Script
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit">
</script>
  • After that, we create a javascript function for google translate on website <div>
<script type="text/javascript">
function googleTranslateElementInit(){
new google.translate.TranslateElement({pageLanguage: 'en'} 'google_translate_element');
}
</script>

Complete Source Code of Google Translate On Website

<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8"/>
<body>
<h1>Integrate Google Translate on website</h1>
<p>Hello Coder!</p>
<p>Translate this complete 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></body>
</html>

Output:

--

--

Bikash Panda

I am a web application developer. FB Community: @mrpandatech, Twitter: @phpcodertech My PHP problem-solving site http://phpcoder.tech