Skip to content

Instantly share code, notes, and snippets.

@vy-nguyen
Created February 1, 2016 06:00
Show Gist options
  • Save vy-nguyen/7fc3a2e15e3f77a867cd to your computer and use it in GitHub Desktop.
Save vy-nguyen/7fc3a2e15e3f77a867cd to your computer and use it in GitHub Desktop.
public class Messages {
// property file is: package/name/messages.properties
private static final String BUNDLE_NAME = "package.name.messages";
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
public static String getString(String key, Object... params ) {
try {
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment