phpjquerywordpressgoogle-translator-toolkit

How to set on load marathi language using google translator in wordpress?


I have used google translator in wordpress but i want to set marathi language on load site but by default it takes english language, here i want to set by default local language without any selection


Solution

  • add this code for your Theme Header (header.php) in head tag:-

    <script type="text/javascript">
            function googleTranslateElementInit() {new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'en,mr,hi', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');}
          var url = window.location.href;    
           if (url=='http://demosite.com'){
              url += '#googtrans(en|mr)';
              window.location.href = url;
            }
        </script>
    

    and this line in your body tag:-

      <div id="google_translate_element"></div>