There are only 2 simple steps
Make your website
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Website</title>
</head>
<body>
<h1 style="text-align:center">Simple Multilingual Website</h1>
<h2 style="text-align:center">Like and follow for more!</h2>
</body>
</html>
Integrate Google translate
To integrate the Google Translate functionality, we will first load the Google translate API script
https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit
After that we will add a
div
on top of the website having idgoogle_translate_element
. In thediv
we load the Google Widget using the below script.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Simple Website</title>
<!-- Loading the Google Translate API -->
<script type="text/javascript" defer src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script defer type="text/javascript">
// assigning the element having id 'google_translate_element' to be the Google translate widget and assigning the default language to be English(en)
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
</head>
<body>
<!-- Below div will act the Google Translate widget -->
<div style="text-align:center" id="google_translate_element"></div>
<h1 style="text-align:center">Simple Multilingual Website</h1>
<h2 style="text-align:center">Like and follow for more!</h2>
</body>
</html>
YEP! That's all. We have our multilingual website ready!
GitHub Gist Link : https://gist.github.com/yashnirmal/282c9e69d13bb2667620d5d94eb631b1
Follow for more Web Dev related content