gpt4 book ai didi

java - 找不到 gettext-commons 资源包

转载 作者:可可西里 更新时间:2023-11-01 11:48:06 25 4
gpt4 key购买 nike

我正在翻译我的桌面 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com