开发者

How can i get all Date/Time format pattern in GWT for different locales

开发者 https://www.devze.com 2023-03-11 23:06 出处:网络
I try to get all date/time format pattern in GWT, using DateTimeFormat.PredefinedForma开发者_Go百科t to get all pattern of the current locale. but how can i get all pattern for an other locale.I found

I try to get all date/time format pattern in GWT, using DateTimeFormat.PredefinedForma开发者_Go百科t to get all pattern of the current locale. but how can i get all pattern for an other locale.


I found a way, not the generic way what i want, but in this case it works. Perhaps has someone a better solution.

   private static Date testDateFormates( String dateText ) {

        ArrayList<String> locales = new ArrayList<String>();

        DateTimeFormatInfo formatDE = new DateTimeFormatInfoImpl_de();
        DateTimeFormatInfo formatEN = new DateTimeFormatInfoImpl_en();
        DateTimeFormatInfo formatFR = new DateTimeFormatInfoImpl_fr();
        DateTimeFormatInfo formatES = new DateTimeFormatInfoImpl_es();
        DateTimeFormatInfo formatZH = new DateTimeFormatInfoImpl_zh();
        DateTimeFormatInfo formatRU = new DateTimeFormatInfoImpl_ru();

        addToList( locales, LocaleInfo.getCurrentLocale().getDateTimeFormatInfo() );
        addToList( locales, formatDE );
        addToList( locales, formatEN );
        addToList( locales, formatFR );
        addToList( locales, formatES );
        addToList( locales, formatZH );
        addToList( locales, formatRU );

        .
        .
        .  
    }

    private static void addToList( ArrayList<String> patterns, DateTimeFormatInfo format ) {
        patterns.add( format.dateFormat() );
        patterns.add( format.dateFormatFull() );
        patterns.add( format.dateFormatLong() );
        patterns.add( format.dateFormatMedium() );
        patterns.add( format.dateFormatShort() );
    }


I don't think you can do this. While building your application the GWT-Compiler creates multiple version of your application for the different locales. One specific version is then loaded by the browser, thus the other locale are not available at runtime. Read up on Deferred Binding if you want to know more: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html

However there is an option to force a certain locale. This can be useful if you only support one locale, or it can be used for testing purposes. Add the following lines to your module XML file:

<inherits name="com.google.gwt.i18n.I18N"/>
<extend-property name="locale" values="en_US"/>
<set-property name="locale" value="en_US"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消