Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I try to get all date/time format pattern in GWT, using DateTimeFormat.PredefinedFormat to get all pattern of the current locale. but how can i get all pattern for an other locale.

like image 660
tomkpunkt Avatar asked Jun 08 '11 08:06

tomkpunkt


2 Answers

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() );
    }
like image 61
tomkpunkt Avatar answered Nov 15 '22 05:11

tomkpunkt


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"/>
like image 34
Adrian B. Avatar answered Nov 15 '22 06:11

Adrian B.