HTML / Script to force translation

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
DarioMartin
 
 
Posts: 32
Joined: Mon Feb 24, 2020 8:37 pm

HTML / Script to force translation

Post by DarioMartin »

I have a dual language site: Spanish / English. I have catered for the site by creating a mirror of each page in both languages. This speeds up load etc when pressing the "Change Language" button. It may not be the most programatically elegant solution - but it works.

However, I have incorporated Google Reviews into my my Testimonials page, using a Widget from Elfsight. works brilliantly, BUT the base language is Spanish.

Is there any HTML code I can insert in the page head to force the page to be translated to English on page load, without user clicking the Google translate option on their browser?

I have found the following code on StackOverflow:

Code: Select all

<script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement({
        pageLanguage: 'es',
        includedLanguages: 'es,en',
      }, 'google_translate_element');
      
      setTimeout(function() {
        // Set the default language to English
        var selectElement = document.querySelector('#google_translate_element select');
        selectElement.value = 'en';
        selectElement.dispatchEvent(new Event('change'));
      }, 1000);
    }
  </script>
Buuuuut .... it doesn't work. Any suggestions?
User avatar
BaconFries
 
 
Posts: 5936
Joined: Thu Aug 16, 2007 7:32 pm

Re: HTML / Script to force translation

Post by BaconFries »

Buuuuut .... it doesn't work. Any suggestions?
Unfortunately we cannot really help with custom scripts. But perhaps the following may help.
Language Text
Google Translate
Post Reply