如何在NetBeans中本地化@Messages注释

如何在NetBeans中本地化@Messages注释,netbeans,localization,internationalization,netbeans-7,netbeans-platform,Netbeans,Localization,Internationalization,Netbeans 7,Netbeans Platform,我想在NetBeans中使用@Messages注释来简化我的应用程序中的本地化。但是,我找不到有关如何使用此机制为其他语言添加翻译(捆绑包)的任何信息 使用@Messages的操作示例如下 @ActionID(category = "category", id = "AddAction") @ActionRegistration(iconBase = "actions/action-icon.png", displayName = "#CTL_AddAction") @ActionReferen

我想在NetBeans中使用
@Messages
注释来简化我的应用程序中的本地化。但是,我找不到有关如何使用此机制为其他语言添加翻译(捆绑包)的任何信息

使用
@Messages
的操作示例如下

@ActionID(category = "category",
id = "AddAction")
@ActionRegistration(iconBase = "actions/action-icon.png",
displayName = "#CTL_AddAction")
@ActionReferences({
    @ActionReference(path = "Menu/Shapes", position = 160),
    @ActionReference(path = "Toolbars/Shapes", position = 5133)
})
@Messages("CTL_AddAction=Add Action")
如何使添加操作因语言而异?

@Messages注释将生成Bundle.java类和Bundle.properties文件。java类将包含用于本地化的函数,Bundle.properties文件包含确定根区域设置的确切字符串的键值对

为了正确地本地化,您应该检查Bundle.properties文件,然后创建Bundle\u fr.properties文件(法语)或Bundle\u whatever.properties文件,其中“whatever”是您希望添加的区域设置

然后,当为应用程序设置语言环境时,Bundle.java类应该使用正确的Bundle_xx.properties文件来本地化对Bundle.java类函数的调用

package com.testmodule;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;

@ActionID(category = "category",
id = "com.testmodule.AddAction")
@ActionRegistration(iconBase = "com/testmodule/action-icon.png",
displayName = "#CTL_AddAction")
@ActionReferences({
    @ActionReference(path = "Menu/Shapes", position = 160),
    @ActionReference(path = "Toolbars/Shapes", position = 5133)
})
@Messages({
    "CTL_AddAction=Add Action"
})
public final class AddAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        Locale.setDefault(Locale.FRENCH);
        System.out.println("I am action "+Bundle.CTL_AddAction());
    }
}
我的包看起来像:

Bundle.properties
    OpenIDE-Module-Name=testmodule
Bundle_fr.properties
    OpenIDE-Module-Name=french testmodule
    CTL_AddAction=Ajouter une action

Bundle.properties已存在。它还包含其他i18n文本。我已经添加了一个本地化的属性文件,但是拾取的文本是默认语言,即使使用NbBundle的其他文本拾取正确的区域设置文本。你会有一个我可以比较的工作例子吗?只是确保。。。您是否使用Bundle.java访问器获取本地化字符串?它应该看起来像Bundle.CTL_AddAction(),我将处理一个示例…我要替换的代码是@Messages({“CTL_AddAction=AddAction”})。我希望“添加操作”将自动被区域设置版本取代,但事实并非如此。所以要么我不懂魔法,要么我做得不好。我在Bundle_fr.properties中有一个本地化的文本,但它没有被拾取。我不知道如何使用注释指定消息。也许,我缺少了一些明显的东西……我添加了Bundle.properties文件的内容,以及一行代码,用于在执行操作时设置默认区域设置。在这一点上,你在我的回答中看到的对我有用。首先,我的操作显示为添加操作(默认区域设置=en,指向默认bundle.properties),然后,一旦我执行了操作,区域设置就会更改,日志和操作也会显示文本。谢谢。我认为我犯的错误是,我在一个子包中定义了操作,我希望它查找基本后台的Bundle.properties文件。因此,我在包中创建了一个新的Bundle.properties,添加了OpenIDE模块名属性,并重新构建了它。非常感谢:)