开发者

GWT Internationalization throws an exception while rebinding

开发者 https://www.devze.com 2022-12-13 00:50 出处:网络
I\'m trying to internationalize a test application with GWT following the instruction and I have: com.example.client.MyConstants.java

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 clas开发者_如何学Gos.                         -->
    <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.

    -


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.


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"/>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号