Madhusudhan
Madhusudhan

Reputation: 331

How to implement Runtime Locales in GWT

I am trying to implement Runtime Locales in GWT, But I could not able to get it working. There is very limited documentation available on net. So could you please help me in implementing Runtime Locales in GWT. It will be helpful if someone give an example on how to implement Runtime Locales, because I have already spent lot of time on implementing Runtime Locales. So if somebody explain how to implement it using an example that would be great.

The reason I need Runtime Locale is, I want to get date format, month names and weekdays names based on locale string (Ex : en_US, es_MX etc), I mean I want to obtain Locale object from locale string as it is possible in Java. As of my knowledge we cannot get information about any other locale than the default locale that GWT has loaded. and i don't want to use Compile time Locales because of the compile time overhead and increase on static footprint.

This is the documentation for implementing Locale in GWT which I am referring - http://www.gwtproject.org/doc/latest/DevGuideI18nLocale.html

Thanks,

Madhusudhan.

Upvotes: 1

Views: 401

Answers (1)

Adam
Adam

Reputation: 5599

I think you miss one important thing about runtime locales:

[...] all locales that GWT knows about that inherit from your compile-time locale will be automatically included [...]

As an example, you might have one set of translations for all of Spanish as spoken in Latin America (es_419), yet allow users to choose a country-specific locale such as Argentinian Spanish (es_AR).

Note that DateTimeFormatInfoImpl_es_AR extends DateTimeFormatInfoImpl_es_419.

But there is a trick that allow you to get date format in any locale by getting DateTimeFormatInfo implementation directly for given locale:

DateTimeFormatInfo format = new DateTimeFormatInfoImpl_es_MX();
format.dateFormatLong(); // d 'de' MMMM 'de' y

Upvotes: 1

Related Questions