How to find correctly the client's locale?

267 views
Skip to first unread message

Sorinel C

unread,
Jul 19, 2010, 4:19:49 AM7/19/10
to Google Web Toolkit
I have used the following code, trying to detect the client's locale,
but always I get the "default" one, which is the EN_US, even if I
change the locale of my system to French, for example.

[code]
final LocaleInfo locale = LocaleInfo.getCurrentLocale();
decimalSeparator = locale.getNumberConstants().decimalSeparator();
thousandSeparator = locale.getNumberConstants().groupingSeparator();
[/code]

So, can anybody advise me what I miss, please?

Thanks!

Sorinel C

unread,
Jul 19, 2010, 4:24:51 AM7/19/10
to Google Web Toolkit
I have in my module .gwt.xml file definition the following lines:

<inherits name="com.google.gwt.core.Core" />
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.i18n.CldrLocales" />
<inherits
name="com.google.gwt.user.theme.standard.StandardResources" />

So, maybe something else is wrong, but I don't catch it :(

Thanks!

PS: some other GWT tricks you can find here: http://ui-programming.blogspot.com/
:-))

Glimpse

unread,
Jul 19, 2010, 10:00:37 AM7/19/10
to Google Web Toolkit
I've renamed my "index.html" to "index.jsp" and I've added the
following line in the <head/> section:

<meta name="gwt:property" content="locale=<%=request.getLocale()%>">

My application now uses the preferred language defined in the
browser's settings.
This works fine!

Stefan Bachert

unread,
Jul 19, 2010, 10:08:51 AM7/19/10
to Google Web Toolkit
Hi,

the startup code detects the locale.
As documented in stockwatcher demo, you could either supply a locale
in the url (query parameter) or put it into host page as a fixed value


Stefan Bachert
http://gwtworld.de

Sorinel C

unread,
Jul 20, 2010, 2:19:34 PM7/20/10
to Google Web Toolkit
@Glimpse

Thank you for the idea. I've tried myself something similar, but
getting the request header "Accept-Language" and I get the browser
language ... but this isn't exactly what I want ...

For example, I have set my systems locale to France, but the browser
(FF & Chrome) have English previously set, and of course, I get the
English language in the request header. My need would be to return the
"system locale" not that setting of the browser language.

Thanks anyways, that solution is patial good ! ... assuming that the
people in France have browser settings for France, the one from Canada
the same Canada (english or french) and so on....

Cheers!
Reply all
Reply to author
Forward
0 new messages