Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » [neon] Changing user language programmatically
[neon] Changing user language programmatically [message #1755600] Mon, 06 March 2017 09:31 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 560
Registered: October 2012
Location: Bern, Switzerland
Senior Member
In Scout Neon applications I can change the application's language by changing my browser language. This information also seems to be stored in a cookie with the name scout.preferredLocale.

Changing language therefore takes a change of the browser language and the deletion of the cookie.

Is there a way to offer the user a menu where they can choose their preferred language and then set this programmatically? Is there a way to persist this automatically, or would that be up to me? Is it just a matter of using NlsLocale.set() or NlsLocale.CURRENT.set()? Or is there more to it?
Re: [neon] Changing user language programmatically [message #1755915 is a reply to message #1755600] Thu, 09 March 2017 09:57 Go to previous messageGo to next message
Adrian Sacchi is currently offline Adrian SacchiFriend
Messages: 10
Registered: January 2013
Junior Member
I created an example for the Contacts demo application with:
https://github.com/BSI-Business-Systems-Integration-AG/org.eclipse.scout.docs/commit/856adb2929c7e185a75de649ca346fe0d0855f2c

The most important part is that you set the locale in execLoadSession() of your AbstractClientSession implementation before the desktop is created.

public class ClientSession extends AbstractClientSession {
  public static final String PREF_USER_LOCALE = "PREF_USER_LOCALE";
  
  ...

  @Override
  protected void execLoadSession() {
    initializeSharedVariables();

    // The locale needs to be set before the Desktop is created.
    String localeString = ClientUIPreferences.getClientPreferences(ClientSession.get()).get(PREF_USER_LOCALE, null);
    if (localeString != null) {
      Locale userLocale = LocaleUtility.parse(localeString);
      setLocale(userLocale);
    }

    setDesktop(new Desktop());
  }
}


The solution with the OptionForm and the ClientUiPreferences is just one possibility. Of course you are completely free in terms of how to present the user with the choice and how to persist this setting.
Re: [neon] Changing user language programmatically [message #1756251 is a reply to message #1755915] Tue, 14 March 2017 14:30 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 560
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks Adrian, that works like a charm!
Previous Topic:[NEON] Overriding org.eclipse.scout.rt.ui.html
Next Topic:[NEON] Hot Swapping UI changes made in Java
Goto Forum:
  


Current Time: Thu Jun 22 12:20:55 GMT 2017

Powered by FUDForum. Page generated in 0.02424 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software