How to install Google Translate Tool to translate DISQUS comments
This is a community integration graciously provided by Marina from HotforWords. Keep in mind we recommend still using our native localization for interface updates. You can find your language options under the forum settings page.
Step 1
At Google's Translate Tools get the following code (which may vary a bit depending on the options you pick):
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Step 2
Insert the following code between the first <script> and function googleTranslateElementInit():
var hotrans = window.location.search.substring(1,document.location.search.length);
Step 3
Then add the following code after the first </script>:
<script>
// Trusty Tran by Cran www.gootar.com
document.write("<a href='"+ window.location.href.replace(/#.*$/,'') + " translate'>Translate</a>");
// get window location. If it has a comment... strip it (and everything after it) out then append ?translate
if (hotrans!="" && hotrans.indexOf('translate')>=0){
document.write("\<script src='//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'\>\</script\>");
}
</script>
Step 4
Remove everything after the </script> tag.
Your final code should look something like this:
<div id="google_translate_element"></div><script>
var hotrans = window.location.search.substring(1,document.location.search.length);
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script>
// Trusty Tran by Cran www.gootar.com
document.write("<a href='"+ window.location.href.replace(/#.*$/,'') + "?translate'>Translate</a>");
// get window location. If it has a comment... strip it (and everything after it) out then append ?translate
if (hotrans!="" && hotrans.indexOf('translate')>=0){
document.write("\<script src='//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'\>\</script\>");
}
</script>
Reminders and Tips
- Don't forget the
<div id="google_translate_element"></div>tag that appears at the top of the code. This is where the dropdown menu appears when you click Translate. <div id="google_translate_element"></div>can be located anywhere in your document.<div id="google_translate_element">can be styled. For example, the following CSS gives the element a yellow background:.goog-te-gadget { background: yellow; margin: 5px 5px 8px; padding: 10px; }You can see it in action here.
Example


