• Resolved slazt

    (@slazt)


    Hi,

    I’m currently optimizing my website. gtmetrix.com & Google PageSpeed Insights both tells me that Google Translate has a Maximum Child Elements of 109
    <select class=”goog-te-combo” aria-label=”Language Translate Widget”>

    By deleting the nodes I see that I just need the languages I chose. So 10 out of 109 languages). Could I optimize this ?

    Thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • in settings, simply uncheck all, then check the ones u want;-)

    Thread Starter slazt

    (@slazt)

    @airdrummer
    Thanks for replying. I have already selected 10 languages. This is not the issue.

    The issue is that Gtranslate create 109 hidden nodes (all languages) and only 10 of them are useful (in my case). If you inspect the code you will find after “.goog-te-combo” all the 109 languages nodes. If I manually delete the useless nodes, translation is still fine. So I tryied to change the .php file but haven’t find for the moment the place where to reduce hidden nodes to 10.
    Anyway, this is an issue because GTmetrics and Google PageSpeed Insights rank your site and it add useless code.

    =>>> Avoid an excessive DOM size
    “A large DOM will increase memory usage, cause longer style calculations, and produce costly layout reflows.”

    Thanks

    Thread Starter slazt

    (@slazt)

    I found the solution. I was using the [Gtranslate] Shortcode but I changed to the widget code displayed in the settings…

    Thread Starter slazt

    (@slazt)

    No in fact, it doesn’t work !
    Back with my issue !!!!

    Need some help ! GTranslate team ??
    Thanks

    i just checked & found that while the div containing the flags & onclick js links is trimmed to just the selected languages, the select.goog-te-combo does indeed contain all languages…inspecting the php Widget code reveals that that div is filled in the browser by javascript:

    <div id="google_translate_element2"></div>
    <script>
    function googleTranslateElementInit2() {new google.translate.TranslateElement({pageLanguage: 'en',autoDisplay: false}, 'google_translate_element2');}
    </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit2"></script>

    and so isn’t limited to just the selected languages:-( fixing it will require passing the list of selected languages to the javascript on the client(browser).
    but the javascipt is google’s, so the fix will require studying that code.

    it should be possible, as the code does have a list[array] of selected languages:
    jQuery(document).ready(function() {var allowed_languages = ["af","sq","am","ar"...

    aha! all that’s needed is

    <script type="text/javascript">
    function googleTranslateElementInit2() {
     new google.translate.TranslateElement({
      // set the following line to the original language:
      pageLanguage: 'en',
      // limit the languages by removing the '//' and listing them:
      // includedLanguages: 'es,fr',
      layout: google.translate.TranslateElement.InlineLayout.SIMPLE
     }, 'google_translate_element');
    }
    </script>

    see https://www.formsite.com/blog/translate-forms-90-languages/

    i’ve added these lines to gtranslate.php:

    496a497,498
    >             widget_code += '\',includedLanguages: \'';
    >             widget_code += implode(',', $allowed_languages);

    but unfortunately that causes the plugin to include _all_ languages:-\
    i gotta go deliver meals, so i’ll leave it up to the plugin author to fix, or u can give it a hack;-)

    Thread Starter slazt

    (@slazt)

    @airdrummer
    I’ve been looking at the code you’ve provided, can’t make it work for the moment, but It’s getting clearer ??
    Thank you so far !!

    ohwait:
    Our paid versions are fully SEO compatible
    so maybe they won’t fix the freebie version…u get what u pay for;-)

    good luck!-)

    Thread Starter slazt

    (@slazt)

    Thanks! ??

    Plugin Author edo888

    (@edo888)

    Hi,

    I’m sure you are fighting with microseconds and measuring the improvement will not be possible. But if you “believe” that it will solve some issues for you, then my advice is to modify only the Widget Code section in GTranslate plugin settings page to not have issues with future updates. You will need to change

    function googleTranslateElementInit2() {new google.translate.TranslateElement({pageLanguage: 'en',autoDisplay: false}, 'google_translate_element2');}

    with

    function googleTranslateElementInit2() {new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'en,fr,de,es,it,...', autoDisplay: false}, 'google_translate_element2');}

    Thanks! ??

    Thread Starter slazt

    (@slazt)

    @edo888 Hi and thanks for the help.
    It’s indeed microseconds, but when I run across “problems” i like to understand and solve them if possible.

    I tried to update the wigdet code section with slight changes (pageLanguage to french et the 10 included languages I use):

    function googleTranslateElementInit2() {new google.translate.TranslateElement({pageLanguage: 'fr', includedLanguages: 'en,es,it,pt,de,fr,ru,nl,ar,zh-CN',autoDisplay: false}, 'google_translate_element2');}

    but it doesn’t seems to change anything. I tried recreate a shortcode section (OceanWP theme / Elementor Pro) or with text editing section…

    I still have these 109 nodes (small issue)

    Thanks for your time

    • This reply was modified 3 years, 6 months ago by slazt.
    Thread Starter slazt

    (@slazt)

    Additional feedback: It works with Chrome but not with Firefox or Edge

    Thread Starter slazt

    (@slazt)

    It actually works fine now!
    Thank for your help @edo888
    Have a nice day

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[GTransalte] Avoid an excessive DOM size’ is closed to new replies.