UPDATE: This method seems to be working again. If it ever stops working again, try GTranslate instead
This is an English expansion of the Google Translate widget script covered in this video: https://www.youtube.com/watch?v=5meQKQhGBZg. Thank you to Programming with Vishal !
To get started, place this script in Tools & Plugins > Custom HTML > Footer:
<script src="https://translate.google.com/translate_a/element.js?cb=loadGoogleTranslate"></script>
<script>
function loadGoogleTranslate() {
new google.translate.TranslateElement ("google_element");
}
</script>
If you'd like to narrow the number of languages down to a specific selection, use "includedLanguages" and add the language code.
Here's an example:
<script src="https://translate.google.com/translate_a/element.js?cb=loadGoogleTranslate"></script>
<script>
function loadGoogleTranslate() {
new google.translate.TranslateElement ({
pageLanguage: "en",
includedLanguages: "am,ny,ht,ha,ig,rw,mg,st,sn,so,sw,xh,yo,zu,bm,ee,kri,ln,lg,om,nso,ti,ts,ak,fr,en",
}, "google_element");
}
</script>
I got this idea from jomocu's Simple Website Translator. Apparently, this improves the privacy of the users by "preventing Google from seeing the IP address of all your clients by proxing the connection". To do so, swap out "https://translate.google.com/translate_a/element.js?cb=loadGoogleTranslate" for "https://corsproxy.io/?https%3A%2F%2Ftranslate.google.com%2Ftranslate_a%2Felement.js%3Fcb%3DloadGoogleTranslate" in the script src="
Here is an example:
<script src="https://corsproxy.io/?https%3A%2F%2Ftranslate.google.com%2Ftranslate_a%2Felement.js%3Fcb%3DloadGoogleTranslate"></script>
<script>
function loadGoogleTranslate() {
new google.translate.TranslateElement ("google_element");
}
</script>
I got this idea from jomocu's Simple Website Translator as well. According to the plugin author, this should improve the loading speed of your website. To do so, add async
berfore the function
.
Here's an example:
<script src="https://translate.google.com/translate_a/element.js?cb=loadGoogleTranslate"></script>
<script> async
function loadGoogleTranslate() {
new google.translate.TranslateElement ("google_element");
}
</script>