Change language by clicking a link

14
So I want to change the language of the whole app by clicking a link. With a simple microflow I change the System Language for the current user, but I might refresh the client? How to do this in the microflow?  Thanks in advance!
asked
7 answers
15

An option, although not widely known, is to use a Javascript snippet (HTMLSnippet is also possible) and use the following code:

mx.reloadWithState()

This code basically reloads your page, but preserves the state of the page (for example, when you are working in a form and have already set some attributes in your page). I have a piece of code you can find here: https://gist.github.com/JelteMX/2fa80d639869cc3b332ad366c76eb2bc. This describes how you can switch the language using a Microflow, and it will reload the page after the microflow is triggered.

Edit: I think this is only applicable in 7.10 and above. It was introduced around that time, but I'd have to check the release notes for that.
 

answered
6

I have made a solution by using this code within a Mendix 8 Javascript Action.

let contentForm = window.mx.ui.getContentForm();
let reloadObject = {
        page: {
            path: contentForm.path,
            trackId: contentForm.getContext().getTrackId(),
            title: contentForm.title
        },
        cache: window.mx.data.dehydrateCache()
    };
window.sessionStorage.setItem('mx.reload', JSON.stringify(reloadObject));
window.mx.reload();

This reloads to the page you are currently on.

answered
4

Hi,

you no longer need to logout/in for the language refresh. But you need a page reload.

You can do that with some javascript.

mx.reloadWithState(); // see answer by Jelte (undocumented API 2018-11-13)

// or

window.location.reload(false);

If you put that in a widget it's also nicely packaged.

regards, Fabian

EDIT: You can use the HTMLSnippet Widget if you don't want to build a dedicated widget.

Put that widget on a popup page. Then open that page from your microflow.

answered
2

Hi Lisa,

To apply the settings, you need to log out and log in. So a message at the end telling the user to do that, would be a user friendly solution.

Regards,

Micha Friede

answered
2

In this forum post some solutions are offered for multilingual anonymous users:

https://forum.mendix.com/link/questions/91676

answered
1

Has somebody tried this trick in Mx 7.20.1? I'm not having success here!

answered
1

Does this still work in Mendix 8? Because here on 8.6 the function 

mx.reloadWithState()

navigates to the homepage.

answered