java - gettext-commons 找不到资源包

标签 java eclipse windows internationalization gettext

我正在翻译我的桌面 Java 应用程序(在 Windows 10 操作系统上),因此我使用 http://code.google.com/p/gettext-commons 中的 gettext-common

我遵循了 gettext-common 提供的教程:https://code.google.com/archive/p/gettext-commons/wikis/Tutorial.wiki

按照我创建的所有步骤,创建 Messages_fr.class,Messages_en.class 问题出在 gettext-common 中,当我创建时,它们有 Messages_en.properties 而不是 .class Messages_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);
    }

我有一个问题:

问题 1:我的消息文件位于 resources/Messages 目录下。它仅包含 2 个文件:messages_en.class 和 messages_fr.class,而不是 messages_fr.properties 和 messages_en.properties。

如果我尝试运行上述代码,我会收到警告:“ResourceBundle [messages],这是因为没有 .properties 文件

最佳答案

对于 java ResourceBundle 存在两种不同的实现:

  • 用于 *.properties 文件的 PropertyResourceBundle,众所周知,延迟部分加载
  • ListResourceBundle,纯java代码,*.class,带数组,快速,完全加载(初始化时间,内存使用)。

根据您的描述,gettext 桥似乎使用 ListResourceBundle 或其自己的 ResourceBundle 实现。没关系。

如图msgfmt从 gettext 文件 (.po) 创建 .class 资源文件。

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

他们关于使用 Maven 的建议可能确实值得。

说了这么多,也许只是使用 Locale.FRENCH

此外,我还看到了 Properties~ 和 ListResourceBundles 之间的区别:可以尝试 "resources/messages" 或注意正确的情况(大写 M)"resources.Messages “

关于java - gettext-commons 找不到资源包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38862479/

相关文章:

java - 从 Java 代码运行 MSVC 编译器会出现错误

java - 将带 collection.size 的 hibernate HQL 转换为条件查询

eclipse "unsurround"选择(删除 try/catch,if etc block )

java - 在哪里可以下载 Eclipse 插件?

eclipse - Sublime Text 2 编辑的文件更改在 Maven 项目中刷新浏览器时不显示

windows - 我如何强制退出 Git Bash?

windows - 当线程阻塞等待事件时,SysInternals 的进程监视器可以记录吗?

java - Spring Autowired 组件在 bean 方法中为 null

java - 发生 org.hibernate.exception.GenericJDBCException : Could not open connection for long running process

java - RabbitMQ 工作队列 : Starting Consumer after Sender [Java]