Change language on a web app

Hi !
I’m new in Xojo and trying to create a multi lingual web app and I have a WebPopupMenu in the webpage. The idea is to change the texts (labels, buttons, etc) based on the language selected on such WebPopupMenu.

I’m using localized strings and this is working.

At webapp start up, the language is recovered from the browser (language header) and copied to the Session.LanguageCode.

What I’m doing is to change Session.LanguageCode based on the WebPopupMenu selection,then invoking Session.GoToURL(Session.URL) to reload the page but this doesn’t work: the page reloads with the browser default language.

What is the right way to perform this?
Thank you!
Antonio

Reloading the page starts a new session, so the selection is lost. The easiest route forward would be to store the new language selection in a cookie. The new session would read the cookie and store the value as needed.

3 Likes

you can specify the language code as a parameter of your constant

Var s As String
s = kHello("fr") ' s = "Bonjour"
s = kHello("en") ' s = "Hello"
s = kHello("en_UK") ' s = "Welcome"

https://documentation.xojo.com/topics/localizing_your_apps/introduction_to_app_localization.html

1 Like