[原]RCP使用org.eclipse.osgi.util.NLS访问资源文件及自动将字符串导出至资源文件的方法
2011-12-04 15:39 hedalixin 阅读(848) 评论(0) 收藏 举报
public class MyMessages extends NLS {
private static final String BUNDLE_NAME = "com.hedalixin"; //$NON-NLS-1$
public static String HELLO_WORLD;
public static String HELLO_SOMETHING;
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, MyMessages.class);
}
}
private static final String BUNDLE_NAME = "com.hedalixin"; //$NON-NLS-1$
public static String HELLO_WORLD;
public static String HELLO_SOMETHING;
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, MyMessages.class);
}
}
资源文件MyMessages.property(上边的类名)的内容还是和以前一样:
HELLO_WORLD=Hello world!
HELLO_SOMETHING=Hello {0}!
HELLO_SOMETHING=Hello {0}!
在程序里使用资源的方式如下:
System.out.println(MyMessages.HELLO_WORLD);
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING,"world"));
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING,"world"));
自动将工程的字符串导出到资源文件中:
右键工程名称>source>Externalize Strings...可自动完成以上步骤。
作者:salc3k 发表于2011-11-5 16:08:44 原文链接
阅读:40 评论:0 查看评论
浙公网安备 33010602011771号