我正在尝试在我的网站上加入谷歌网站翻译。我想使用自动内容,因此如果您的浏览器语言与页面语言不同,则会显示该栏。每次我选择自动显示模式时,它给我的代码是'tabbed'。任何人都可以告诉我我做错了什么或提供正确的代码吗?
提前致谢。
编辑:
<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>
答案 0 :(得分:2)
我在这里看到另一个例子:
Detect User's Preferred Language and Google Translate Automatically
这个参数autoDisplay:false,
要在网站语言不匹配时仅获取翻译栏我已删除容器,并使用autoDisplay:true,
我用另一种语言得到了标准,但没有下降。
答案 1 :(得分:2)
在试图找出autoDisplay无法正常运行的原因时,即始终显示翻译菜单时,我找到了W3C国际化检查器:http://validator.w3.org/i18n-checker/
W3C国际化检查员提醒我接受标题正在返回: Accept-Language:en-US,en; q = 0.8
我最初粘贴到我的网站文件中的Google生成的代码只有一个值来检查页面语言。但我编辑了它,见下文,并将一个数组传递给pageLanguage键,我认为它现在正在工作。
<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的任何人身上。您可以将任何语言传递给阵列,以根据您的需要正确配置它。
如果有人对此有任何反馈,我会很感激。希望它有所帮助。
答案 2 :(得分:1)
<div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'id', includedLanguages: 'id', 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>
答案 3 :(得分:0)
要仅在您的页面与用户页面不同时显示翻译器,请进行服务器端检查,并在必要时仅包含代码。
您的网址不正确。添加“http:”。见下面的工作示例。
<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="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
答案 4 :(得分:0)
Funny how Google's code retrieval for the translator automatic function is broken, isn't it? I tried many iterations in the Rincewind level Wizard they have to do the custom setup, but the default was to a Tabbed function that doesn't fit with my website design.
This is for an English site, change the language code for your site default language where the bar isn't supposed to display. Remove the tracking if you're not using it.
<!-- <div id="google_translate_element"></div> -->
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: true,
layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
gaTrack: true, gaId: 'UA-xxxxxx-x'
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
答案 5 :(得分:0)
#include "i2c.h"
#include <xc.h>
#include <htc.h>
/*
* subroutine: I2C_INIT()
* access from: main.c/BOOT()
* description: Initialisises MSSP port for I2C Master-Mode
*/
void I2C_INIT(0)
{
TRISCbits.TRISC3=1; //config SCL-Line as Input;
TRISCbits.TRISC4=1; //config SDA-Line as Input;
SSP1CON1 = 0b00101000;
/*
* bit 5: Enables the serial port and configures the SDA and SCL pins as the
* source of the serial port pins
*bit 0-3: 1000: I2C Master Mode, clock = FOSC/(4*(SSPASS+1))
*/
SSP1CON2 = 0x00;
SSP1ADD = 39; //clock = FOSC/(4*(SSPASS+1)) - 100 kHz @ 16MHz FOSC
SSP1STAT = 0b11000000;
/*
* bit 7: Slew rate control disabled for standard speed mode (100 kHz and 1 MHz)
* bit 6: Data transmitted on rising edge of SCK
*/
}
答案 6 :(得分:-1)
<div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false, multilanguagePage: true}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
答案 7 :(得分:-1)
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'es',
includedLanguages: 'es',
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>