0

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??????

Tarish Saini
  • 340
  • 1
  • 5
  • 14
  • What do you mean by browser locale? – Andrei Volgin Jan 31 '13 at 06:42
  • Say if I change my browser locale to japanese then my UI loads in jp_JP locale through gwt dictionary but as gwt datepicker dose not use gwt dictionary for localization its not loading in jp_JP locale isted of that it loads in en default locale. Any idea how to do it????? – Tarish Saini Jan 31 '13 at 06:54
  • You may want to read a bot more about browsers and locales: http://stackoverflow.com/questions/673905/best-way-to-determine-users-locale-within-browser – Andrei Volgin Jan 31 '13 at 08:46

3 Answers3

1

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.

Till
  • 994
  • 5
  • 18
1

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.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Does GWT datepicker supports differed bindings???, as I dont see any tags in datepicker.gwt.xml file. – Tarish Saini Jan 31 '13 at 10:06
  • I was talking about `com.google.gwt.i18n.client.impl.DateTimeFormatInfoImpl`, `GWT.create()`d from `com.google.gwt.i18n.client.impl.LocaleInfoImpl`. – Thomas Broyer Jan 31 '13 at 10:44
  • Thanks Thomas, DateTimeFormatInfoImpl's object is created in LocaleInfoImpl, if I need to override it using rules it should be placed in I18n.gwt.xml file. I'm bit confused about it, Can you please elaborate the implementation a bit more. – Tarish Saini Feb 04 '13 at 09:08
  • It doesn't matter where `` rules come from so a) extend `DateTimeFormatInfoImpl`, b) add a `` in your module to replace `DateTimeFormatInfoImpl` with your subclass. – Thomas Broyer Feb 04 '13 at 09:50
  • Hi Thomas, com.google.gwt.i18n.shared.DefaultDateTimeFormatInfo has the code which I want to replace with my subclass, I did that Please find below code: – Tarish Saini Feb 05 '13 at 05:22
  • and my class syntax is : public class OTSDefaultDateTimeFormatInfo implements DateTimeFormatInfo Code gets compiled but at run time it dosent show my changes with my subclass. m I doing something wrong here?? – Tarish Saini Feb 05 '13 at 05:27
  • Thanks Thomas, It did worked for me, what I was doing wrong is that I was creating that class in my helper package where as it should be in client package. :) – Tarish Saini Feb 05 '13 at 08:28
1

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

jat
  • 61
  • 3