• Resolved Chuckie

    (@ajtruckle)


    I am currently using this approach to determine the selected language:

    How to detect current selected language? | GTranslate Help Center

    /*
    * If original language is selected, then the value of current_language
    * will be empty. Otherwise, it will contain the current selected
    * language code.
    *
    */
    var current_language = gt_get_cookie('googtrans').split('/').pop();

    // W3 Schools: https://www.w3schools.com/js/js_cookies.asp
    function gt_get_cookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
    c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
    return c.substring(name.length, c.length);
    }
    }
    return "";
    }

    It works fine. But the problem is that I must use F5 to reload the page after the user changes the language. Otherwise the cookie doesn’t reflect the new setting.

    This is not a hardship. But, I have a drop-down language selector at the top right on the site, available on all pages. Is it not possible to extract the value from there? This way my tawk.to form will function properly (at-least for English and Italian).

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author edo888

    (@edo888)

    Hi,

    Not sure why you need to refresh to see the new cookie when you change the language. If you provide more details about what you are trying to do, I might try to help better.

    If you are having issues with Tawk.to, I recommend skipping it from translation.

    Thanks! 🙂

    Thread Starter Chuckie

    (@ajtruckle)

    The problem is that the widget doesn’t get re-created when the user changes the language in the drop-list. It is most likely created when the page is first displayed.

    I am trying to look into displaying translation of the widget in another ticket, but that in itself is not enough. It needs to re-create the widget as each languages widget is tied into a localized knowledge base.

    Plugin Author edo888

    (@edo888)

    If it is to change the tawk.to interface language, then you will need our paid version: https://gtranslate.io/#pricing

    Thanks! 🙂

    Thread Starter Chuckie

    (@ajtruckle)

    the problem is not gtranslate and I do not need paid version.

    when the page loads my JavaScript executes. But when I select a language in my combo (interfaces changes) for my JavaScript code does execute understandably. Unless I refresh. I will ask tawk.to

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Detecting selected language’ is closed to new replies.