How i change the locale language of the application

2,779 views
Skip to first unread message

Eduardo Cardoso

unread,
Oct 21, 2008, 1:58:36 PM10/21/08
to google-web-toolkit
WITHOUT refreshing a page and no use of  ?locale=en_US after url?
 
something like : setLocale(new Locale.BR) and the page refresh all text data.
 
regards
 
Eduardo

Ian Petersen

unread,
Oct 21, 2008, 3:20:53 PM10/21/08
to Google-We...@googlegroups.com
On Tue, Oct 21, 2008 at 1:58 PM, Eduardo Cardoso
<cardoso...@gmail.com> wrote:
> WITHOUT refreshing a page and no use of ?locale=en_US after url?
>
> something like : setLocale(new Locale.BR) and the page refresh all text
> data.

As far as I know, you can't do that with GWT's built-in i18n support.
If you don't like the ?locale=en_US in the URL, you can avoid it by
writing <meta> tags into the HEAD section of your host page, but,
regardless, you'll have to refresh the page. Why do you want to avoid
the refresh? If you're worried about losing application state, look
into GWT's history support.

Ian

Eduardo Cardoso

unread,
Oct 22, 2008, 12:57:38 AM10/22/08
to Google-We...@googlegroups.com
Hmmm, good idea! I will take a look.
 
Thank very much

Lothar Kimmeringer

unread,
Oct 22, 2008, 3:36:55 AM10/22/08
to Google-We...@googlegroups.com
Eduardo Cardoso schrieb:

> WITHOUT refreshing a page and no use of ?locale=en_US after url?

At the moment, when using Messages or Constants you can't do that
because the different languages are realized with different HTML-
pages that must be loaded when changing the locale.

> something like : setLocale(new Locale.BR) and the page refresh all text
> data.

I'm thinking about this as well for a while because there are
projects where the change of the Locale during runtime is a
explicit requirement ruling out GWT at the moment.

You can solve that using GWT by not using the Constants/Messages-
framework but with the Dictionary-classes but that eliminates
the advantages you have with the interfaces allowing you to do
the compiler the job of checking the correct spelling of the keys.


Regards, Lothar

Lothar Kimmeringer

unread,
Oct 22, 2008, 3:41:57 AM10/22/08
to Google-We...@googlegroups.com
Ian Petersen schrieb:

> Why do you want to avoid the refresh?

You mean, why do we need AJAX? We don't need it but if we have it
(here with GWT) there shouldn't be any exceptions.

> If you're worried about losing application state, look
> into GWT's history support.

I know it's a way but it's a very complicated way if you "only"
want to exchange the texts of all widgets that are implementing
HasLocalizableText (an interface I just made up right now ;-)

As the OP said, he just want to do a setLocale(new Locale.BR)
to change all localizable data on the page without caring what
the current state of the page is. That's nothing new, e.g.
Casabac (bought and abadoned by Software AG) allowed exactly that.


Regards, Lothar

Ian Petersen

unread,
Oct 22, 2008, 9:57:26 AM10/22/08
to Google-We...@googlegroups.com
On Wed, Oct 22, 2008 at 3:41 AM, Lothar Kimmeringer <j...@kimmeringer.de> wrote:
> Ian Petersen schrieb:
>> Why do you want to avoid the refresh?
>
> You mean, why do we need AJAX? We don't need it but if we have it
> (here with GWT) there shouldn't be any exceptions.

No, I meant, "what's your reason?" not "why would you possibly want
that?!"--I was just trying to see if, for example, history support or
meta tags were enough to solve the problem.

>> If you're worried about losing application state, look
>> into GWT's history support.
>
> I know it's a way but it's a very complicated way if you "only"
> want to exchange the texts of all widgets that are implementing
> HasLocalizableText (an interface I just made up right now ;-)
>
> As the OP said, he just want to do a setLocale(new Locale.BR)
> to change all localizable data on the page without caring what
> the current state of the page is. That's nothing new, e.g.
> Casabac (bought and abadoned by Software AG) allowed exactly that.

Yeah, I kind of agree but with one really big caveat: the user's
locale seems like something that won't change much. I think, ideally,
it should change at most once because you should be able to sniff the
user's desired locale out of their HTTP request headers and, if you
have user accounts, you could store the user's preferred locale in
your database and make sure to set the correct locale every time they
log in.

I guess I'm saying that, to me, the trade off of (presumably) more
efficient i18n in exchange for having to request a new page to change
the locale is a fine one.

Ian

Gambogi

unread,
Oct 22, 2008, 1:38:02 PM10/22/08
to Google Web Toolkit
So, for the first moment, i need change only the language of the text
on the page.
But, i have some difficult with reload() or other refresh methods
because their lost the gwt state.
For example, if i change the language on first page, its ok , because
the following pages will work with the new language without i need to
set this again.
But, in my application, i can set this language in all following
pages.But, with the query string solution its works but my application
lose all state and return to the first page.Using the property
solution (gwt:property content="locale=blablabla") , i change that on
html with javascript, but its dont changed anything, only the
property, and its only work if i refresh the page again (also losing
the gwt state).
I take a look on GWT's history support and i dont see anything which
be usefull in my problem.
So, somebody have more tips about this case?

best regards

Eduardo

Rana Issa

unread,
Jul 5, 2012, 6:56:08 PM7/5/12
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Hi,

I am also, not finding a way to set the locale in GWT. The only way I  found is to use a query parameter that will re-load the page. However, although the url locale is changed,the actual page doesn't change the language.
Does anyone know why does this happen?

The code for changing the url:

public static void changeLocale(String localeParamName, String newLocale) {
UrlBuilder newUrl = Window.Location.createUrlBuilder();
newUrl.setParameter(localeParamName, newLocale);
Window.Location.assign(newUrl.buildString());

Rana

unread,
Jul 17, 2012, 3:50:58 AM7/17/12
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Hi,

I found the problem!
In the module file I need to set the order of search:
<set-configuration-property name='locale.searchorder' value='queryparam,cookie,useragent' />
I had a space so, it caused GWT not to function well
<set-configuration-property name='locale.searchorder' value='queryparam, cookie, useragent' />  //that caused the issue.

Issue solved
Rana
Reply all
Reply to author
Forward
0 new messages