Google网站翻译器自动显示模式 [英] Google Website Translator Automatic Display Mode

查看:261
本文介绍了Google网站翻译器自动显示模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上加入google网站翻译器.我想使用自动功能,因此如果您的浏览器语言与页面语言不同,则会显示该栏.每次我选择自动显示模式时,它给我的代码都是制表符".谁能告诉我我做错了什么或提供正确的代码?

I'm trying to include google website translator on my website. I want to use the automatic thing so the bar shows up if your browser language is different to the page language. Every time I select the automatic Display mode the code it gives me is for 'tabbed'. Can anybody tell me what i'm doing wrong or provide the right code?

谢谢.

<div id="google_translate_element"></div>
<script type="text/javascript">
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({pageLanguage: 'en', layout:     google.translate.TranslateElement.FloatPosition.TOP_LEFT},     'google_translate_element');
    }
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

推荐答案

在试图弄清autoDisplay不起作用的原因(即始终显示翻译菜单)时,我发现了W3C国际化检查器:

While trying to figure out why the autoDisplay was not functioning, i.e. the translate menu always displayed, I found the W3C Internationalization Checker: http://validator.w3.org/i18n-checker/

W3C国际化检查器提醒我,接受标头正在返回: 接受语言:en-US,en; q = 0.8

The W3C Internationalization Checker alerted me that the Accept Headers were returning: Accept-Language: en-US,en;q=0.8

我最初粘贴到网站文件中的Google生成的代码只有一个值可以检查页面语言.但是我对其进行了编辑(请参见下文),并将一个数组传递给pageLanguage键,我认为它现在可以正常工作.

The code generated by Google that I originally pasted into my site files only had one value to check the page language. But I edited it, see below, and passed an array into the pageLanguage key and I think it's now working.

<div id="google_translate_element"></div>
<script type="text/javascript">
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({pageLanguage: ['en', 'en-us'], autoDisplay: false, multilanguagePage: true, gaTrack: true, gaId: 'UA-403844-8'}, 'google_translate_element');
    }
</script>
<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

我通过更改Google Chrome中的语言设置来尽我所能进行测试.但是我不完全相信它能正常工作.对于在浏览器中未配置en或en-US的任何人,都应该显示翻译菜单.您可以将任何语言传递给阵列,以根据需要进行适当的配置.

I ran tests as best I could by changing the language settings in Google Chrome. But I don't fully trust that it's working. The translate menu ought to appear for anyone without en or en-US configured in their browsers. You could pass in any language to the array to properly configure it for your needs.

如果有人对此有任何反馈,我将不胜感激.希望对您有所帮助.

If anyone has any feedback on this I'd appreciate it. Hope it helps.

这篇关于Google网站翻译器自动显示模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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