2011-11-24 38 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),这......令我是几乎无用。

缺乏在这方面的文件。