Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically Translate Website based on URL Parameter using Google Translate

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.

like image 922
daniel_c05 Avatar asked Jan 11 '23 02:01

daniel_c05


1 Answers

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

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

like image 81
user1819575 Avatar answered Feb 03 '23 08:02

user1819575