谷歌翻译设置默认语言 [英] Google Translate set default language

查看:336
本文介绍了谷歌翻译设置默认语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这有一个明显的解决方案,我忽略了,但我似乎无法找到正确的参数来实现这一点。
使用网站上的Google翻译小部件,我需要设置用户在进入网站时看到的默认语言,即使该网站是英语。

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');
}

我尝试添加:
defaultLanguage:'fr'
并尝试:
targetLanguage:'fr'

我确实找到了一些不错的jQuery解决方案,但如果这是一个简单的解决方案,我不想绕过它。

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

推荐答案

这不是直接回答如何使用jQuery来完成任务,但希望它有用。谷歌翻译使用名为googtrans的cookie来跟踪选择的语言。您可以在页面加载之前自己设置该Cookie,Google翻译将使用它。

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');

这篇关于谷歌翻译设置默认语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆