Tarish Saini
Tarish Saini

Reputation: 340

Browser specific GWT Datepicker Loaclization

GWT Datepicker is showing in "en" locale even if I change my locale to some other language. I dont want to specify it in some *.gwt.xml file, what I want is that it should take it from browser locale. Any workaround for this??????

Upvotes: 0

Views: 672

Answers (3)

jat
jat

Reputation: 61

If you want to use the browser locale (which is generally going to be pretty limited, not available in all cases, etc), then you want the combination of Thomas's answer (specifically specifying all the locales your app should support in extend-property tags) and setting the locale.useragent property (you don't need to set locale.searchorder unless you want to change the order or disable some provider).

Specifically, in your apps gwt.xml file, add the following:

<inherits name="com.google.gwt.i18n.I18N"/>
<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr"/>
... etc ...
<set-configuration-property name="locale.useragent" value="Y"/>

You don't need any replace-with rules. See GWT i18n docs

Upvotes: 1

Thomas Broyer
Thomas Broyer

Reputation: 64541

Dynamic I18N as they call it is only about providing translated constants. For everything else (number formatting, date formatting, plural rules, etc.) you have to compile the supported locales within your app (<extend-property name="locale" values="…" />).

As an alternative, you can possibly override (using <replace-with> rules) the various implementations (in your case with DatePicker, the DateTimeFormatInfoImpl) with your own that would get their information from a Dictionary (or equivalent) rather than from compiled-in data. These APIs are subject to change between versions of GWT though (and I can already tell you that they will change in GWT 2.6).

In the end, it's probably easier to recompile your GWT app when you add support for a new locale, than go down the above-mentioned road.

Upvotes: 1

Till
Till

Reputation: 994

GWT does not use the browser locale by default. You have to tell it to do so.

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

Be aware of that this does not work with all browsers. I suppose that's why it's not activated by default. So far IE is the only exception I know of.

Upvotes: 1

Related Questions