Changing User Language - mx.reloadWithState() not working (properly)

3
Hi Everyone, I am trying to let the user have the option to change the user language via a dropdown on a page.   I followed the instructions in the Mendix Ref Guide: https://docs.mendix.com/refguide/translatable-texts/ So I used the mx.reloadWithState JavaScript Snippet on a Pop-Up page and calling/showing that page in the microflow in which I am changing the language.   It seems to do what it’s supposed to do and refreshes the page but the language doesn’t change. For some reason it takes a while (sth. like 10-20 seconds) and if I refresh then the language changes.  I can see that the user language gets changed correctly for the account and also the rest of the logic seems to work fine, except the translated texts are not showing. If I use the debugger and go through the microflow step by step it’s working perfectly. It almost feels like the browser / cache needs some time to get the translation ;)  I tried a couple of things yesterday (different browsers, nanoflow instead of microflow, playing around with the refresh in client, having a delay before calling the “reload” pop-up and so on) and now I’m out of ideas and really clueless what’s the cause for this.   I’d appreciate any help/idea how to fix this. Thanks in advance! Also I will put a more detailed description of the setup below.   Cheers Jan     More detailed description of the setup: Since it was requested to show language options in their respective language I created a “LanguageSelector” Entity associated with the User Account (1-1) with an enumeration attribute containing those different language options. Since I’m using the account object on a data view on that page I simply put a dropdown for the language selection on the respective page and added a on-change event with the microflow for changing the language → retrieving the System.Language depending on the selection → changing the account / user language to that language →  committing the changes → calling the pop-up with mx.reloadWithState JavaScript snippet
asked
4 answers
3

Okay, with the commit (ugly) it seems to work as expected… so I guess this will also work for your case? In your case you’ll have a drop down with the available languages and an on change event that triggers a similar NF I guess.

Setup:
Login screen which accepts anonymous users and contains translated text (and a translated button) in three languages (Dutch, German, English). To switch languages, the user can click a button. Buttons are inside a Dataview that uses a microflow to fetch the language of the current user (to hide a language button if the current language is the one from the button).

Each button triggers a NF that does the following:
- calls a MF that retrieves a System.Language object by language code (nl_NL, en_US, de_DE, etc).
- if this language is different than the current language, the language is set for the current user (and committed)
- if the language was different, the JavaScript mx.ReloadWithState() is called

The result:

answered
1

Using an answer field to be able to add an attachment, but it’s really a comment…

As you can see, it doesn’t always work as intended ;-)

Setup:

Simple login screen
Button which switches language on the current anonymous user (retrieves a language entity by language code and sets that on the current user).
If the language was detected to be different than before, we call mx.ReloadWithState() and the page gets reloaded
Debug text shows what should be expected.
1) When the screen is first shown to the user, it’s in Dutch (as expected)
2) When we press the button to switch to English, this time around, it’s all English (so as expected)
3) When we switch back to Dutch, the detected language shows nl_NL (Dutch), which is as expected, however, all text is still in English.
4) If we continue this way, sometimes the text will match the language, sometimes not...

answered
0

Hi , 

Create a JavaScript Action with a Code as mx.reloadWithState and call it in the Nanoflow .

Use the Nanoflow under the Button you want to Switch Language . It will work for sure .

it works for me for one of the App

answered
0

I’m also having this problem.  I’m working with 9.18.0.
But local or on DEV, no problems, it only occurs on ACC en PRD where we have more users.  It appears there’s a delay.

In my case, all the text and buttons on the screen change perfectly (with htmlsnippet, with mx.reloadWithState())..  But the buttons where you choose the language sometimes don’t change with it and the apperance is dependent on $currentuser/language.  Also when this happens the first error messages aren’t translated as well.

Page in Dutch, error in German.

answered