views:

574

answers:

3

I'm trying to internationalize a test application with GWT following the instruction and I have:

com.example.client.MyConstants.java
com.example.client.MyConstants_en.properties
com.example.client.MyConstants_fr.properties
com.example.client.MyAppEntryPoint.java

In this code I have:

public interface MyConstants extends Constants
{
      @DefaultStringValue("HelloWorld")
      String hellowWorld();
}

And

public class MyAppEntryPoint implements EntryPoint
{
    public void onModuleLoad()
    {
     MyConstants constants = GWT.create(MyConstants.class);

     VerticalPanel mainPanel = new VerticalPanel();
     mainPanel.add(new Label(constants.hellowWorld()));
     RootPanel.get("myContainer").add(mainPanel);
    }
}

For MyApp.gwt.xml I have:

<module rename-to="myModule">
    <inherits name="com.google.gwt.xml.XML" /> 
        <inherits name="com.google.gwt.i18n.I18N"/>

    <inherits name='com.google.gwt.user.theme.standard.Standard'/>

    <!-- Specify the app entry point class.                         -->
    <entry-point class='com.example.client.MyAppEntryPoint'/>

    <extend-property name="locale" values="en,fr"/>
</module>

In the html I have:

...

It all seems to work as long as I don't include in the xml file. As soon as I do, I get the following exception:

[ERROR] Generator 'com.google.gwt.i18n.rebind.LocalizableGenerator' threw threw an exception while rebinding 'com.example.client.myConstants'
java.lang.NullPointerException: null
...

Any help would be greatly appreciated on why it's throwing the exception.

    -
A: 

It could be the extend-property doesn't accept multiple values. I think you should write:

<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr"/>
Hilbrand
The GWT sample code has "<extend-property name="locale" values="en,fr" />"
Stephane Grenier
+1  A: 

The answer is that the module name has to be the same as the properties name. So if I use:

<module rename-to="MyApp">

Then the properties files need to be:

com.example.client.MyAppConstants.java
com.example.client.MyApp_en.properties
com.example.client.MyApp_fr.properties

In other words, the module name has to be the same as the properties files.

Stephane Grenier
A: 

After trying different options I figured, you don't need "en" option, I guess because that is the default hence you need: com.example.client.MyAppConstants.java (Interface) com.example.client.MyAppConstants.properties (Default) com.example.client.MyAppConstants_fr.properties (Other language)

Hopefully this helps someone else's time.

seba