• Resolved rbergeron81

    (@rbergeron81)


    When the page loads, Facet text (e.g. Dec 1 – Setting the Stage for COP29) does not get translated until you click one of the filters.

    I tried using a function/script to trigger the translation on facetwp-loaded, but it doesn’t run because “Weglot is not defined”

            add_action( 'facetwp_scripts', function() {
    ?>
    <script>
    // Function to trigger Weglot translation
    function triggerWeglotTranslation() {
    if (typeof Weglot !== 'undefined') {
    Weglot.translate();
    }
    }

    // Run on initial FacetWP load
    document.addEventListener('facetwp-loaded', function() {
    triggerWeglotTranslation();
    });

    // Run on FacetWP refresh
    document.addEventListener('facetwp-refresh', function() {
    triggerWeglotTranslation();
    });
    </script>
    <?php
    }, 100 );

    Any ideas on how I can fix this or what I am doing wrong?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Edson Galina Fortes

    (@glx77)

    Hi @rbergeron81 ,
    hope you’re fine? Sorry for the issue you’re facing. I think you try to use the weglot js object but using the plugin this object is not declare by default.

    to use it you have to initialize the object in JS using : Add a json collection of selector css you need to translate.

    <script type="text/javascript" src="https://cdn.weglot.com/weglot.min.js"></script>
    <script>
    Weglot.initialize({
    api_key: 'YOUR_API_KEY',
    hide_switcher: true,
    whitelist: {},
    });
    </script>

    Let me know if it’s help

    Regards

    Thread Starter rbergeron81

    (@rbergeron81)

    Hi, that didn’t seem to work. We are using the Weglot WordPress plugin. Is there some other way that this can be done?

    Plugin Contributor Edson Galina Fortes

    (@glx77)

    On my side it seems to work , the facet seems to be translate . Can you provide a screenshot to be sure ?

    Thread Starter rbergeron81

    (@rbergeron81)

    Sorry, ya, I found a different solution or rather workaround that seems to work. I am triggering a refresh of the FacetWP facets shortly after page load which causes the translation to run as well. Here is the script if anyone needs it:

    // Function to trigger Weglot translation
    document.addEventListener('DOMContentLoaded', function () {
    // Trigger facet refresh after 0.2 seconds
    setTimeout(function () {
    FWP.refresh();
    console.log('FacetWP refreshed!');
    }, 200);
    });



Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.