I have something like:
String text = "The user {0} has email address {1}."
// params = { "Robert", "myemailaddr@gmail.com" }
String msg = MessageFormat.format(text, params);
This isn't great for me, because sometimes my translators are not sure what goes in the {0} and {1}, also it would be nice to be able to reword the messages without worrying about the order of the args.
I'd like to replace the arguments with readable names instead of numbers. Something like this:
String text = "The user {USERNAME} has email address {EMAILADDRESS}."
// Map map = new HashMap( ... [USERNAME="Robert", EMAILADDRESS="myemailaddr@gmail.com"]
String msg = MessageFormat.format(text, map);
Is there an easy way to do this?
Thanks! rob