MessageFormat
1061 ワード
リソースファイルのプレースホルダの使用
error_message=CI {0} not found {1}
public class ResourceBundleUtils {
static ResourceBundle messages;
static {
if (messages == null) {
Locale currentLocale;
currentLocale = new Locale("en", "US");
messages = ResourceBundle.getBundle("conf/ErrorMessagesBundle",
currentLocale);
}
}
public static void main(String[] args) {
System.out.println(ResourceBundleUtils.getMessage("error_message"));
String[] s = {"test"};
System.out.println(ResourceBundleUtils.getMessage("error_message", s));
}
public static String getMessage(String key) {
return messages.getString(key);
}
public static String getMessage(String key, String[] args) {
String s = messages.getString(key);
return MessageFormat.format(s, args);
}
}