4

Till now, our web application supports only English. Now we have to provide support for Italian as well. There is GWT module for some functionality. To support the Italian language I have added below line in the file "APP_Module.gwt.xml"

<extend-property name="locale" values="it"/>

I have also placed "XXX_it.properties" file under the source code where the properties file for en is kept.

Setting the locale in the jsp by following line:

<meta name="gwt:property" content="locale=${locale}">

Now, the issue is how to compile the code. I am debugging the application but it is not hitting the client code of GWT presented under WEB-INF/src.

I am very new to GWT. Please suggest how can I compile the code or there is no need of compilation. It will automatically take the changes done in "APP_Module.gwt.xml" and there is some other issue. How can I see logs of GWT?

Community
  • 1
  • 1
Infotechie
  • 1,653
  • 6
  • 23
  • 35

2 Answers2

3

To add support for locales to GWT application, you need to do the following in your xxx.gwt.xml:

under <module> add this to include the support:

<inherits name="com.google.gwt.i18n.I18N" />

and this to configure it:

<extend-property name="locale" values="en,it"/>
<set-property-fallback name="locale" value="en"/>

Add all your property files under some package like this:

src/main/resources/foo/bar/client/i18n/MyMessages.properties
src/main/resources/foo/bar/client/i18n/MyMessages_it.properties

Then you need to tell GWT to compile them into classes. This is example from a pom.xml file (if you don't use maven, you will have to use a different way, but you still need to configure it).

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>1.3.1.google</version>
            <executions>
                <execution>
                    <goals>
                        <goal>i18n</goal>
                        <goal>generateAsync</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <i18nMessagesBundles>
                    <resourceBundle>foo.bar.client.i18n.MyMessages</resourceBundle>
                </i18nMessagesBundles>
            </configuration>
        </plugin>

Then you need to recompile the code. In maven mvn compile. And that's all, you will have your messages in generated sources folder ready to use.

MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
  • Most of the information can be found here: https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n – MartinTeeVarga May 29 '13 at 07:22
  • Thanks @sm4 Its working fine. But now what happening is the characters like ù,ì are not displayed correctly. Is there any place where we set encoding? – Infotechie May 30 '13 at 11:19
  • This is most likely because you are putting UTF-8 (or any other encoding) into .properties directly. These files must be in ISO-8859-1 encoding. Try using the plugin from this question: http://stackoverflow.com/q/863838/1667977 Correct way is to have all special characters in properties escaped, this plugin will do it for you. – MartinTeeVarga May 30 '13 at 11:24
  • And of course your jsp page hosting the script can define encoding like this: `` – MartinTeeVarga May 30 '13 at 11:26
  • I am loading the properties file in GWT using blow line GWT.create(propertiesFile.class); any idea in which encoding this reads the properties file? – Infotechie May 30 '13 at 12:31
  • This is a wrong question. You are creating the class using GWT deferred binding. This has nothing to do with encoding. Encoding of the property file that gets compiled into a class is ISO-8859-1 and you tried to put there UTF-8 (or else) character. Use the plugin and you will see the difference. – MartinTeeVarga May 31 '13 at 02:27
  • Tried ResouceBundle tool as well but no difference still wrong characters are displayed.Any other option? – Infotechie Jun 04 '13 at 06:43
  • Then maybe it's time to create a new question :) Last thing, try playing with the page encoding in your jsp using tag – MartinTeeVarga Jun 04 '13 at 06:57
  • Hope to see you answering on new question :) Thanks!! – Infotechie Jun 04 '13 at 07:12
0

For seeing the logs of gwt you can use gradlew gwt also you can use it to compile the code too.

jerin john
  • 203
  • 1
  • 4
  • 11