Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Website Translator Automatic Display Mode

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?

Thanks in advance.

EDIT:

<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>
like image 556
user2532030 Avatar asked Jun 28 '13 13:06

user2532030


People also ask

Why is Google not automatically translating?

Enable Translate Prompts Expand the Advanced section to the left side of the Settings panel, and then click Languages. Next, click Language under Languages (right-side of the window) to reveal additional options. Ensure that the switch next to 'Offer to translate pages that aren't in a language you read' is set to on.

Why is my Google translating automatically?

By default, Google auto translation is enabled in both Google Chrome and when using Google Toolbar. The auto translation feature lets Google automatically translate the text on Web pages where the text is from a language you don't speak into a language that you do.


2 Answers

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/

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

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>

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.

like image 119
podoglyph Avatar answered Oct 17 '22 19:10

podoglyph


I saw another example here:

Detect User's Preferred Language and Google Translate Automatically

This had the parameter autoDisplay: false,

To get only the translation bar when the site language doesn't match I have deleted the container, and used autoDisplay: true,

I get the bar when in another language, but no drop down.

like image 34
gm-sb Avatar answered Oct 17 '22 18:10

gm-sb