Created
February 1, 2016 06:00
-
-
Save vy-nguyen/7fc3a2e15e3f77a867cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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