getCurrentLang() to return the language code on form submission page

Hello all,

Does anyone know how to use getCurrentLang() to know the language code for a multi-language website?

I currently use Weglot for the translation and there is not much instruction on how to use getCurrentLang() on their site: Javascript functions - Weglot


Here is my site Read-Only: [LINK][Webflow - Priceloop Website (Final version)]
(how to share your site Read-Only link)

Might try…

let language = Weglot.getCurrentLang();
console.log(language);

Which should get the Weglot-selected language.
If you want the user’s actual browser-set language;

let language = navigator.language || navigator.userLanguage;
console.log(language);
1 Like

Hi @memetican

Thanks for your response.
Can you please let me know where I should add the above code: add another element, or add in the or that page?

Btw, is it possible to return the language code in Webflow’s logic (flow):

You’re trying to feed it into a logic flow?
Since the flow is form-triggered, in the triggering page-

  1. add a plain text field, named Language Code
  2. give that field an ID lang-code
  3. add script to your page before-head or before-body, to auto-populate that field.
  4. publish and test on webflow.io
  5. bind it to your Logic flow
  6. Once you know it’s working smoothly, you can hide it ( display: none on the style panel, not visibility: hidden on the settings panel, they’re very different ).
<script defer>
window.addEventListener('DOMContentLoaded', (event) => {
    let language = Weglot.getCurrentLang();
    let inputField = document.getElementById('lang-code');
    if (inputField) {
        inputField.value = language;
    }
});
</script>

Hi @memetican ,

I tried the code but there are a few errors that I cannot fix:

  1. it returns “undefined” as the field value
  2. in the logic flow, it says that “the variable requires a fallback”

Screenshot 2023-07-21 at 22.43.11

I have no idea how to fix these. Can you please help me out with this?
Thank you !!!

Here is my read-only site: Priceloop website

You’ll have to check with Weglot on getting the language code if you’re using their service for that. If you need help researching that bit, you can direct message me and I’ll send you my rates.

For the logic fallback, you just set the fallback value in logic. Logic docs cover that, click the little yellow icon.

Not sure what your design goal here is, if you have a default language when Weglot does not have one selected, I’d just set that in the field and/or as the fallback.

1 Like

Hey @memetican,

Thanks for your reply.
I think the Weglot logic flow does not work in my case or at least I couldn’t figure out a way to do it.

But I managed to get the form url displayed on the backend, so it sort of solves the issue.
Thank you very much for all your assistance and help!!!