Automatically Translate Website based on URL Parameter using Google Translate
This should help... just pass it into the URL like this:
https://support.google.com/translate/?hl=en#2643150
daniel_c05
Updated on June 05, 2022Comments
-
daniel_c05 about 2 years
I have a Website which currently is only in English. However, we have a Google Translate widget which will translate the website to any language selected by the user. Here's the small snippet:
<div id="google_translate_element"></div> <script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement( { pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } </script> <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Now, I will be routing some traffic from Spanish speaking users to the site. Considering I know these are spanish speaking users, is there any call I can make on the code to Automatically translate the website to Spanish (i.e to simulate a user selecting a given option on the Translate)? I'd be using a specific URL param, such as for example lang=spa.
I tried browsing the code that gets inserted when the DIV is loaded, but it was just a very messy code to even look at.
Has anyone tried such thing, can you provide a code bit to follow up from?
Thanks.
-
daniel_c05 over 10 yearsI feel so lazy for not finding that answer, which is on a public help page... Thanks a lot!
-
coupdecoop over 8 yearsThanks! If for some reason that page moves, here's the important bit: "To do this, add #googtrans(en|TARGET_LANG_CODE) to the end of your site's URL" e.g. stackoverflow.com/#googtrans(en|es) for spanish.