Tuesday, June 4, 2013

Re: How to change the application locale dynamically

Another nicer (imho) solution is to use cookie.

In your gwt.xml (locale.cookie could be whatever you want):

<set-configuration-property name="locale.cookie" value="gwtLocale"/>

By default GWT uses following search order:

<set-configuration-property name="locale.searchorder" value="queryparam,cookie,meta,useragent"/>

You can modify it according to your needs. To actually change the locale you have to: 

Cookies.setCookie("gwtLocale", "ja_JP");
Window.Location.reload();

Greg

On Monday, June 3, 2013 4:32:48 PM UTC+2, David Levesque wrote:
Here's how I do it from a ClickHandler:

    UrlBuilder builder = Window.Location.createUrlBuilder();
    builder.setParameter("locale", localeName);
    String url = URL.decodeQueryString(builder.buildString());
    Window.Location.replace(url);

where localeName is the locale code, e.g. "en_US".

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment