Multi-State box with multilingual doesn't work fine

I’m currently working for the first time on a website with three languages, I chose to work with Multi-state box and code.

When I switch from Hebrew (the main language) to English and then to Russian, everything works fine and the states change accordingly, but when I go back to Hebrew - it stays in the previous state.

I have a feeling I’m missing something. Attach the code as an image. Working with Wix Editor.
I would appreciate any help :slightly_smiling_face:

import wixWindowFrontend from 'wix-window-frontend';

$w.onReady(function () {
    const language = wixWindowFrontend.multilingual.currentLanguage;
    if (language === 'he') {
		$w("#statebox1").changeState("State1");
    }
	else {
		if (language === 'en') 
			$w("#statebox1").changeState("State2");
        else
			$w("#statebox1").changeState("State3");
    }
});

The question is → HOW DO YOU SWITCH LANGUAGES ?

a) Do you make a page refresh ?
b) Do you click a button?

Mistakes you should not do in future anymore…

  1. Do provide the whole code, related to your issue.
    You are showing only an excerpt of your code.

  2. Do not show CODE as a → PIC/IMAGE ← anyone want to invest time to retype your code from an image. (Time is money and money is time).

  3. Always describe your issue as most detailed as possible.

    1. What kind of editor you use?
    2. What kind of setup was done on your page?
    3. Which elements were used in your project?
    4. Do you have running BACKEND-CODE?

And so on and so on…

  1. Complete your IF-ELSE-CONDITIONS like the following example…
   if (...) {...do something...}
   else {...do something else...}

Doing it the way you do → makes your code look incomplete and in more complex code, you will loose the overview over your code.

but when I go back to Hebrew - it stays in the previous state

And again the question —> how do you go back to HEBREW ?

Hey Dima, thanks for your reply.
I’ve been editing my question and have added a code.

For your questions: I’m using the Language Menu component to switch between the languages, so this is how I’m going back to Hebrew.
I’m using the preview mode, so maybe when I publish the website, it’ll work fine?

Thanks.

This is still not good!

Here is what should work…

import wixWindowFrontend from 'wix-window-frontend';

$w.onReady(()=> {let msb=$w("#statebox1"); console.log('Page is ready...');
    const language = wixWindowFrontend.multilingual.currentLanguage;
    if (language==='he') {msb.changeState("State1"); console.log('STATE-1');}
	else if(language==='en') {msb.changeState("State2"); console.log('STATE-2');}
    else if(language==='ru') {msb.changeState("State3"); console.log('STATE-3');}
    else {console.log('No matching LANGUAGE was found!!!'); console.log('STATE-X');}
});

You have to know, that a changement of a MSB-State (msb=multi-state-box), requires in your case always a page-refresh. That means the page has always to be reloaded to run the IF-ELSE-CONDITION and check which LANGUAGE is currently running.

Check the OUTPUT inside of your CONSOLE!

And yes, always try to debug your code on a → PUBLISHED WEBSITE!