Page 1 of 1

HTML / Script to force translation

Posted: Fri Apr 25, 2025 3:20 pm
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?

Re: HTML / Script to force translation

Posted: Fri Apr 25, 2025 8:04 pm
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