Google Website Translator Automatic Display Mode

前端 未结 8 1421
轮回少年
轮回少年 2020-12-20 14:37

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 langu

相关标签:
8条回答
  • 2020-12-20 15:07

    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.

    0 讨论(0)
  • 2020-12-20 15:09

    To display the translator only when your page is different from the user's page, have a server side check and only include the code if necessary.

    See Getting Browser Language

    Your URL is incorrect. Add "http:". See working example below.

    <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>
    
    0 讨论(0)
提交回复
热议问题