Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Maybe this has an obvious solution that I'm overlooking, but I can't seem to find the correct parameter to put in to make this happen. Using the Google Translate widget on a site, I need to set the default language that the user sees when entering the site, even though the site is english.

function googleTranslateElementInit() {
    new google.translate.TranslateElement({
       pageLanguage: 'en'
    }, 'google_translate_element');
}

I've tried adding: defaultLanguage: 'fr' and tried: targetLanguage: 'fr'

I did find some nice jQuery solutions, but didn't want to bypass this if it was an easy fix.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
626 views
Welcome To Ask or Share your Answers For Others

1 Answer

This isn't a direct answer to how to use jQuery to accomplish the task, but hopefully it's helpful. Google Translate uses a cookie called "googtrans" to track which language is selected. You can set that cookie yourself before the page loads and Google Translate will use it.

// PHP code sample, could be accomplished with any language that can set cookies
// set the default language translation to Portugese
setcookie('googtrans', '/en/pt');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...