Automatically Translate Website based on URL Parameter using Google Translate
Asked Answered
C

1

5

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.

Cowled answered 4/3, 2014 at 5:51 Comment(0)
A
10

This should help... just pass it into the URL like this:

https://support.google.com/translate/?hl=en#2643150

Aeniah answered 5/3, 2014 at 1:7 Comment(3)
I feel so lazy for not finding that answer, which is on a public help page... Thanks a lot!Cowled
Thanks! 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.Tonsillotomy
Looks like this link doesn't work, I tried finding the new url but couldn't. Could anyone help me please?Henigman

© 2022 - 2024 — McMap. All rights reserved.