Is it possible, with resource bundles and MessageFormat to have the following result?
- when I call
getBundle("message.07", "test")
to get"Group test"
- when I call
getBundle("message.07", null)
to get"No group selected"
Every example I found on the Internet is with planets, with files on the disk and so on.
I only need to check if one parameter is null
(or doesn't exist) in the resource bundle's properties file. I hope to find a special format for the null parameter something like {0,choice,null#No group selected|notnull#Group {0}}
.
The method I use to get the bundles is:
public String getBundle(String key, Object... params) {
try {
String message = resourceBundle.getString(key);
if (params.length == 0) {
return message;
} else {
return MessageFormat.format(message, params);
}
} catch (Exception e) {
return "???";
}
}
I also call this method for other bundles, like
getBundle("message.08", 1, 2)
=>"Page 1 of 2"
(always parameters, no need to check fornull
)getBundle("message.09")
=>"Open file"
(no parameters, no need to check fornull
)
What should I write in my .properties file for message.07
to have the result described?
What I have now is:
message.07=Group {0}
message.08=Page {0} of {1} # message with parameters where I always send them
message.09=Open file # message without parameters