Setting locales in gwt.xml do not work

后端 未结 3 1604
天命终不由人
天命终不由人 2020-12-11 22:43

In my module xml file I have this:

 
 
 

        
3条回答
  •  情书的邮戳
    2020-12-11 23:37

    I got an error while running application because of invalid your gwt.xml.

    [Fatal Error] :13:53: Element type "set-configuration-property" must be followed by either attribute specifications, ">" or "/>".
    

    put a space before value as shown below:

     
    

    I have posted a answer in the same context.

    Please have a look at How do I set locale to GWT DateBox

    Screenshot for German(de) locale:

    enter image description here

    Screenshot for French(fr) locale:

    enter image description here


    Complete Code:

    Note: just change com.gwt.test.client.GWTTestProject it with you actual Entry Point clas in your gwt.xml file.

    gwt.xml

    
    
    
        
        
        
        
        
    
        
        
    
        
        
    
        
        
        
        
    
        
        
    
        
        
        
    
    
    

    Entry Point class

    import java.util.Arrays;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Map;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.client.DateTimeFormat;
    import com.google.gwt.i18n.client.DefaultDateTimeFormatInfo;
    import com.google.gwt.i18n.client.LocaleInfo;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_de;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_en;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_es;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_fr;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_ru;
    import com.google.gwt.i18n.client.impl.cldr.DateTimeFormatInfoImpl_zh;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.datepicker.client.DateBox;
    
    public class GWTTestProject implements EntryPoint {
    
    public static final native String getLanguage() /*-{
        return navigator.language;
    }-*/;
    
    public void onModuleLoad() {
        System.out.println(Arrays.toString(LocaleInfo.getAvailableLocaleNames()));
    
        loacleDate();
    }
    
    public void loacleDate() {
        Map formats = new HashMap();
    
        DefaultDateTimeFormatInfo formatDE = new DateTimeFormatInfoImpl_de();
        DefaultDateTimeFormatInfo formatEN = new DateTimeFormatInfoImpl_en();
        DefaultDateTimeFormatInfo formatFR = new DateTimeFormatInfoImpl_fr();
        DefaultDateTimeFormatInfo formatES = new DateTimeFormatInfoImpl_es();
        DefaultDateTimeFormatInfo formatZH = new DateTimeFormatInfoImpl_zh();
        DefaultDateTimeFormatInfo formatRU = new DateTimeFormatInfoImpl_ru();
    
        formats.put("de", formatDE);
        formats.put("en", formatEN);
        formats.put("fr", formatFR);
        formats.put("es", formatES);
        formats.put("zh", formatZH);
        formats.put("ru", formatRU);
    
        for (String key : formats.keySet()) {
            System.out.println(key + " - " + formats.get(key).dateFormat());
        }
    
        String language = getLanguage();
    
        DefaultDateTimeFormatInfo format = formats.get(language);
        DateTimeFormat dateFormat = null;
        if (format == null) {
            dateFormat = DateTimeFormat.getFormat(LocaleInfo.getCurrentLocale()
                    .getDateTimeFormatInfo().dateFormatShort());
        } else {
            dateFormat = DateTimeFormat.getFormat(format.dateFormatFull());
        }
    
        System.out.println("Date formatted:" + dateFormat.format(new Date()));
    
        DateBox dateBox = new DateBox();
        dateBox.setFormat(new DateBox.DefaultFormat(dateFormat));
        RootPanel.get().add(dateBox);
    }
    }
    

    HTML

    
    
    
    
    
    Web Application Starter Project
    
    
    
    
    
    
    

提交回复
热议问题