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

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

问题描述

我正在尝试在我的网站上包含谷歌网站翻译器.我想使用自动功能,以便在您的浏览器语言与页面语言不同时显示栏.每次我选择自动显示模式时,它给我的代码都是选项卡式".谁能告诉我我做错了什么或提供正确的代码?

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 国际化检查器:http://validator.w3.org/i18n-checker/

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.

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

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