Home > Forum > Forms > Webcon Form & Language Switch

Webcon Form & Language Switch
0

Hi community!

We are currently facing a new requirement, where it should be possible to change the browser language with a series of buttons in the form (approximately 20 different languages).

Every click on a language button should change UI labelling on current form to selected button language.

e.g.

[German] [English] [French] ... <-- HTML field

[Form content goes here]

I know this is possible with different browser languages, but is this possible with button action (and maybe some javascript) directly on the form?


Thanks a lot in advance for your help & best regards, Nik

MVP

Hi Nik,

it's easier than I would have guessed. You only need to set the language code an reload the page. :)

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.location = document.location.href //reload, if the language has been set successfully.
}
};

xhttp.open("POST", "/account/setlanguage/langcode/en-US", true); //Set the language
xhttp.send();


Best regards,
Daniel

MVP
In reply to: Nikolaus Schusser

Always a great answer and a great solution.

That seems to be an undocumented REST endpoint, right?

Thanks Daniel, I owe you a beer ;-)

Hi Nik,

it's definitely an unofficial API call so it could change over time without a notification. :)
I found it by recording the network traffic when I changed the language.

I hope there will be a WEBCON Day this year maybe we can see each other there. :)

Best regards,
Daniel