Ric*_*old 5 netbeans localization internationalization netbeans-platform netbeans-7
我想@Messages在NetBeans中使用注释来简化我的应用程序中的本地化.但是,我找不到任何有关如何使用此机制为其他语言添加翻译(包)的信息.
使用的动作示例@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")
Run Code Online (Sandbox Code Playgroud)
如何根据语言改变添加操作?
http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/NbBundle.Messages.html
@Messages注释将生成Bundle.java类和Bundle.properties文件.Bundle.java类将包含用于本地化的函数,Bundle.properties文件包含用于确定根区域设置的确切字符串的键值对.
为了正确本地化,您应该检查Bundle.properties文件,然后创建Bundle_fr.properties文件(用于french)或Bundle_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());
}
}
Run Code Online (Sandbox Code Playgroud)
我的捆绑包看起来像:
Bundle.properties
OpenIDE-Module-Name=testmodule
Bundle_fr.properties
OpenIDE-Module-Name=french testmodule
CTL_AddAction=Ajouter une action
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2389 次 |
| 最近记录: |