Java 找不到gettext commons资源包

Java 找不到gettext commons资源包,java,eclipse,windows,internationalization,gettext,Java,Eclipse,Windows,Internationalization,Gettext,我正在翻译我的桌面java应用程序(在Windows10OS上),所以我使用的是gettext common 下面是gettext common提供的教程: 通过执行所有步骤,我得到了createMessages\u fr.class,Messages\u en.class问题在于gettext common,它们有Messages\u en.properties而不是.class,当我(手动)创建Messages\u en.properties时,它可以工作!而且我不能手动操作,这将花费很长时

我正在翻译我的桌面java应用程序(在Windows10OS上),所以我使用的是gettext common

下面是gettext common提供的教程:

通过执行所有步骤,我得到了create
Messages\u fr.class
Messages\u en.class
问题在于gettext common,它们有Messages\u en.properties而不是.class,当我(手动)创建Messages\u en.properties时,它可以工作!而且我不能手动操作,这将花费很长时间(我有700多句话)

JAVA代码:

static I18n i18n = I18nFactory.getI18n(ParserTest.class,
            "resources.messages");

    public static void main(String args[]) {

        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                print("First run");
            } else {
                print("Second run");
                i18n.setLocale(Locale.FRANCE);
            }

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

    }

    private static void print(String text) {
        System.out.println(text);
    }
static I18n I18n=I18nFactory.getI18n(ParserTest.class,
“资源、信息”);
公共静态void main(字符串参数[]){
对于(int i=0;i<2;i++){
如果(i==0){
打印(“首次运行”);
}否则{
打印(“第二次运行”);
i18n.setLocale(Locale.FRANCE);
}
打印(“当前区域设置:+i18n.getLocale());
打印(i18n)
.tr(“本文本标记为翻译,已翻译”);
字符串标记=i18n
.marktr(“本文本标记为翻译,但未翻译”);
打印(标记);
印刷品(i18n.tr(标记));
mark=i18n.tr(“这是要翻译的{0}.text”,
“聊天(名词)”;
打印(标记);
mark=i18n.tr(“这是要翻译的{0}.text”,
“聊天(动词)”;
打印(标记);
打印(i18n.tr(“聊天(名词)”);
打印(i18n.tr(“聊天(动词)”);
打印(“”);
}
}
私有静态无效打印(字符串文本){
System.out.println(文本);
}
我对此有一个问题:

问题1:我的邮件文件位于
资源/邮件
目录下。它只包含两个文件:messages\u en.class和messages\u fr.class而不是messages\u fr.properties和messages\u en.properties


如果我尝试运行上述代码,我会收到一条警告:“ResourceBundle[messages],这是因为java ResourceBundle没有.properties文件,因此存在两种不同的实现:

  • PropertyResourceBundle用于*.properties文件,众所周知,延迟部分加载
  • ListResourceBundle,纯java代码,*.class,带数组,快速,完全加载(初始化时间,内存使用)
根据您的描述,gettext桥似乎使用了ListResourceBundle或它自己的ResourceBundle实现

如图所示,从gettext文件(.po)创建.class资源文件

gettext过程从所有语言的模板开始,即.pot,然后是每种语言的.po文件

他们关于使用maven的建议可能真的很有价值

都说了,可能只是使用了
Locale.FRENCH


我也看到了Properties~和ListResourceBundle之间的区别:人们可能会尝试
“resources/messages”
或注意正确的大小写(大写字母M)
“resources.messages”

我决定使用PropertyResourceBundle,所以我按照所有步骤进行操作,然后跳转(我不打算创建
.class
),所以我使用with
--properties output
选项来创建.properties而不是.class

赞扬:

msgcat --properties-output msgs/fr.po -o src/com/i18n/Messages_fr.properties
或者创建shell脚本po2pr.sh(./po2pr.sh fr)

java代码:

public class I {

    private static I18n getI18n() {
        I18n getI18n = I18nFactory.getI18n(I.class, "i18n.Messages");
        Locale Locale = new Locale("fr");
        getI18n.setLocale(Locale);
        return getI18n;
    }

    public static String tr(String str) {
        return getI18n().tr(str);
    }

    public static String tr(String text, Object o1) {
        return getI18n().tr(text, o1);
    }

    public static String tr(String text, Object o1, Object o2) {
        return getI18n().tr(text, o1, o2);
    }

    public static String tr(String text, Object o1, Object o2, Object o3) {
        return getI18n().tr(text, o1, o2, o3);
    }

    public static String tr(String text, Object o1, Object o2, Object o3,
            Object o4) {
        return getI18n().tr(text, o1, o2, o3, o4);
    }

    public static String tr(String text, Object[] objects) {
        return getI18n().tr(text, objects);
    }

}
注:

1-您必须创建
消息\u fr.属性


2-确保您在色调级别创建了资源包
src.com.i18n.Messages

谢谢@Joop_Eggen的回复,我已经尝试了“resources/Messages”并使用大写字母M,但仍然找不到资源包,现在我正在尝试创建一个包含all.class的jar文件,看看它是否有效。
public class I {

    private static I18n getI18n() {
        I18n getI18n = I18nFactory.getI18n(I.class, "i18n.Messages");
        Locale Locale = new Locale("fr");
        getI18n.setLocale(Locale);
        return getI18n;
    }

    public static String tr(String str) {
        return getI18n().tr(str);
    }

    public static String tr(String text, Object o1) {
        return getI18n().tr(text, o1);
    }

    public static String tr(String text, Object o1, Object o2) {
        return getI18n().tr(text, o1, o2);
    }

    public static String tr(String text, Object o1, Object o2, Object o3) {
        return getI18n().tr(text, o1, o2, o3);
    }

    public static String tr(String text, Object o1, Object o2, Object o3,
            Object o4) {
        return getI18n().tr(text, o1, o2, o3, o4);
    }

    public static String tr(String text, Object[] objects) {
        return getI18n().tr(text, objects);
    }

}