2009-12-03 101 views
1

我想國際化測試應用程序使用GWT following the instruction拋出一個異常,我有:GWT國際化而重新綁定

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

在這段代碼,我有:

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

而且

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); 
    } 
} 

對於MyApp.gwt.xml我有:

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

在HTML我有:

...

這一切似乎只要我沒有在XML文件中包含的工作。當我這樣做,我得到以下異常:

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

任何幫助,爲什麼它拋出異常不勝感激。

    -

回答

1

答案是模塊名稱必須與屬性名稱相同。所以,如果我使用:

<module rename-to="MyApp"> 

然後屬性文件需要:

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

換句話說,模塊名稱必須是一樣的屬性文件。

0

這可能是延長,酒店不接受多個值。我認爲你應該寫:

<extend-property name="locale" values="en"/> 
<extend-property name="locale" values="fr"/> 
+0

GWT示例代碼具有「」 – 2009-12-04 16:31:41

0

想我想通不同的選項後,你不需要「恩」選項,我猜是因爲這是默認的,因此你需要:

com.example.client.MyAppConstants.java (Interface) 
com.example.client.MyAppConstants.properties (Default) 
com.example.client.MyAppConstants_fr.properties (Other language) 

希望這有助於別人的時間。