Reputation: 26655
I've got my localized messages in a resource bundle file that the JSTL <fmt>
taglib can use. Now I also want to use these messages from inside my Java code. How can it be done?
What I need is something like getMessage()
for a key and getParameterizedMessage()
for a key with parameters.
Update The following seems to work:
ResourceBundle messages = ResourceBundle.getBundle("messages");
String str = messages.getString("PF1");
System.out.println(str);
Object[] messageArguments = {
"test"
};
MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(messages.getString("IT4"));
String output = formatter.format(messageArguments);
System.out.println(output);
Upvotes: 1
Views: 2864