Setting locales in gwt.xml do not work

gwt module selection
gwt properties files
gwt constants
gwt:property
gwt language
gwt sample showcase
inherits name com google gwt user user
gwt documentation

In my module xml file I have this:

 <module rename-to="UIGenerator">
 <inherits name="com.google.gwt.http.HTTP" />
 <inherits name="com.google.gwt.xml.XML" />
 <inherits name="com.google.gwt.i18n.I18N" />
 <inherits name="com.google.gwt.i18n.CldrLocales" />
 <set-configuration-property name="locale.useragent"value="Y" />
 <extend-property name="locale" values="de" />
 <extend-property name="locale" values="fr" />
 <set-property name="locale" value="de, fr" />
 <set-property-fallback name="locale" value="de" />
 <entry-pointclass="mypackage.UIGeneratorEntryPoint" />
 </module>

But every time when I try to use locales it returns me default one which is English.

   LocaleInfo.getAvailableLocaleNames(); this return Array of String with only one value   - default 

IF I set It works but only for German without others!

Thank you in advance!

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:

<set-configuration-property name="locale.useragent" value="Y" /> 

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:

Screenshot for French(fr) locale:


Complete Code:

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

gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='gwttestproject'>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name='com.google.gwt.user.User' />
    <inherits name="com.google.gwt.http.HTTP" />
    <inherits name="com.google.gwt.xml.XML" />
    <inherits name="com.google.gwt.i18n.CldrLocales" />

    <inherits name='com.google.gwt.user.theme.clean.Clean' />
    <inherits name="com.google.gwt.i18n.I18N" />

    <set-configuration-property name="locale.searchorder"
        value="cookie,queryparam" />
    <set-configuration-property name="locale.useragent"
        value="Y" />

    <extend-property name="locale" values="de" />
    <extend-property name="locale" values="fr" />
    <set-property name="locale" value="de, fr" />
    <set-property-fallback name="locale" value="de" />

    <!-- Specify the app entry point class. -->
    <entry-point class='com.gwt.test.client.GWTTestProject' />

    <!-- Specify the paths for translatable code -->
    <source path='client' />
    <source path='shared' />

</module>

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<String, DefaultDateTimeFormatInfo> formats = new HashMap<String, DefaultDateTimeFormatInfo>();

    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

<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="GWTTestProject.css">
<title>Web Application Starter Project</title>
<script type="text/javascript" language="javascript"
    src="gwttestproject/gwttestproject.nocache.js"></script>
</head>
<body>

</body>
</html>

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​  First keep in mind that i18n locale do not work well under gwt: run-codeserver, so you must tested after full compilation. And there is no reason for this two lines, just eliminate them to make it work:

Make sure that you set the locale for your app - either in HTML, or through a URL parameter. For example, you can include this in your HTML:

<meta name="gwt:property" content="locale=de">

Also, remove these lines:

<set-configuration-property name="locale.useragent"value="Y" />
<set-property name="locale" value="de, fr" />

I am following the examples offered in GWT guide, and I never had a problem with locales.

GWT represents locale as a client property whose value can be set either using a for the locale client property is entirely a function of your module configuration. Thus, only the exact code required by the end user is downloaded, no more. The com.google.gwt.i18n.I18N module defines only one locale by default, called default. This default locale is used when the locale client property goes unspecified in deployment. The default locale is used internally as a last-resort match between a Localizable interface and a localized resource or class.

First keep in mind that i18n locale do not work well under gwt: run-codeserver, so you must tested after full compilation.

And there is no reason for this two lines, just eliminate them to make it work:

<set-configuration-property name="locale.useragent"value="Y" />
<set-property name="locale" value="de, fr" />

Ignore my last patch because it was not setting the fallback property to the correct So, a javascript function, getLang(), is called from within myApp.gwt.xml, and  [ERROR] Unable to find 'xml.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source? Firstly, I do not have a 'xml.gwt.xml'. I don't know from where GWT is picking it up. Secondly, I reverted back to 1.4.62, but still the problem persists. I have cleaned-up the eclipse project, created a new GWT

<set-property-fallback name="locale" value="en"/> does not appear to work as to the .gwt.xml file to set a fallback locale: <set-property-fallback name="locale"  The getElementById(String) method will retrieve the Element with the specified ID. If you want to use ID’s in your XML, you’ll need to supply the name of the attribute to use as the ID in the DTD of the XML document (just setting an attribute named id will not work). The getElementsByTagName(String) method is useful if you want to retrieve one or more elements with a particular tag name.

<set-property-fallback name="locale" value="en"/> What I want to do is to tell GWT permutations. I know I can fix this by just running the app in the default locale, but the GWT docs specifically recommend NOT doing this, see When WorkingModule.gwt.xml is compiled, the compiler will produce only an ie6 variant using the default locale; this will speed up development compilations. The output from the WorkingModule.gwt.xml will be a drop-in replacement for MyModule.gwt.xml because the compiler will generate the output using the alternate name.

After creating an object, you can use these methods to retrieve the values Locale. Values. to. a. Module's. XML. File. As mentioned previously, GWT requires is produced for every value of the locale property set in the module's XML file. First of all, you will need a valid GWT module to host your test case class. Usually, you do not need to create a new module XML file - you can just use the one you have already created to develop your GWT module. But if you did not already have a module, you might create one like this: <module> <!-- Module com.example.foo.Foo --> <!--

Comments
  • What you have mentioned in gwt.xml?
  • Its working as expected here is my output [default, de, de_AT, de_BE, de_CH, de_DE, de_LI, de_LU, fr, fr_BE, fr_CA, fr_CH, fr_FR, fr_LU, fr_MC, fr_SN]
  • Any error are you getting while running application?
  • No I do not have errors, but the date that I would like to print is on default english language in I use above xml. Even that I pass locale as parameter in URL
  • I've seen your post yesterday. But It still doesn't work: Every time me date in GWT Box is on default language if I do not specified the language explicitly with set-property, but this work only for specified property
  • The screenshot is showing a German locale (de), not a French one.
  • Sorry, I have tested it with German as well as French. My mistake. Let me change it. Let me do it for you. Working on it. I will come back it still its not working as expected. I am not good in language. :)
  • Its working just you have pass locale=fr in URL as query string and Refresh the page. I have tested with fr and de locale. Should I share the complete code?
  • Could you please share the complete code and is my gwt.xml file is properly set?
  • IT is the same again. GWT Uses default language wich is English even that I have removed these two lines
  • Sorry my friend It is the same again. I see only default language in Locales
  • How are you using the locale? How are you printing this date?
  • dateBox.setFormat(new DateBox.DefaultFormat(dateFormat)); dateBox.setValue(new Date()); Where dateBox is DateBox gwt Object
  • dateBox.setFormat(dateFormat);