2011-11-24 63 views
0

我需要翻譯我的應用程序,所以我要使用gettext,共同從http://code.google.com/p/gettext-commonsgettext的,常見的例子不工作

我檢查了SVN,並試圖編譯示例:

javac -classpath ../java I18nExample.java 
java -classpath ../../target/gettext-commons-0.9.6.jar:. I18nExample 

該程序不會給我目標輸出;我完全不知道發生了什麼事!

看起來de.properties完全被忽略。如果我在Factory的構造函數中將屬性文件設置爲"de",我會得到一部分我想看到的輸出。

在互聯網上有沒有任何地方的java的gettext的工作示例?

這是從示例腳本輸出:

First run 
This text is marked for translation and is translated 
This text is marked for translation but not translated 
This text is marked for translation but not translated 
Four: 4 
chat 
chat 
1 file is open 
2 files are open 
Second run 
This text is marked for translation and is translated 
This text is marked for translation but not translated 
This text is marked for translation but not translated 
Four: 4 
chat 
chat 
1 file is open 
2 files are open 
+0

你能提供一個簡單的例子,說明什麼是工作而不工作? –

+0

http://code.google.com/p/gettext-commons/source/browse/#svn%2Ftrunk%2Fsrc%2Fexamples這就是例子 - 當我運行所有字符串都在en,而不是部分在 – reox

+0

你可能希望針對示例代碼提出問題,或者至少建議他們詳細說明構建過程,如果在構建過程中創建了包。 –

回答

1

有幾個問題,可能是由於在生成過程。

首先,對於消息的查找工作,我需要的ende資源進入Messages_en.propertiesMessages_de.properties爲了做一個真正的資源包。

其次,示例代碼嘗試使用沒有可用翻譯的消息,如「文件已打開」的東西。這裏是我嘗試的更新版本;這一切似乎與上面的修改工作:

public static void main(String[] args) { 
    I18n i18n = I18nFactory.getI18n(I18nExample.class, "Messages"); 
    for (int i = 0; i < 2; i++) { 
     if (i == 0) { 
      print("First run"); 
     } else { 
      print("Second run"); 
      i18n.setLocale(Locale.GERMAN); 
     } 

     print("Current locale: " + i18n.getLocale()); 

     print(i18n.tr("This text is marked for translation and is translated")); 

     String mark = i18n.marktr("This text is marked for translation but not translated"); 
     print(mark); 
     print(i18n.tr(mark)); 

     mark = i18n.tr("This is the {0}. text to be translated", "chat (noun)"); 
     print(mark); 

     mark = i18n.tr("This is the {0}. text to be translated", "chat (verb)"); 
     print(mark); 

     print(i18n.tr("chat (noun)")); 
     print(i18n.tr("chat (verb)")); 

     print(""); 
    } 
} 

還要注意插入翻譯的話,你需要的東西是這樣的:

print(i18n.tr("This is the {0}. text to be translated", i18n.tr("chat (noun)"))); 
print(i18n.tr("This is the {0}. text to be translated", i18n.tr("chat (verb)"))); 

但是,如果沒有聯合國撞(去除!和提供英語翻譯Messages_en.properties,它顯示爲chat (noun),這......令我是幾乎無用。

缺乏在這方面的文件。