Came across this issue, while implementing i18n using spring resource bundle, for a spring based java project, which has a html+js UI.
I need to read all content from a properties file, for a particular locale, and pass this info to the client side, so that the relevant messages can be shown on the UI.
However, the ResourceBundleMessagesource/ReloadableResourceBundleMessagesource objects seem to allow retrieving only a single message at a time.
ReloadableResourceBundleMessageSource msgSource = new ReloadableResourceBundleMessageSource();
//Methods to get only a single message at a time
String message = msgSource.getMessage("edit.delete.success", null, new Locale(localeString));
I am currently using java.util.ResourceBundle, and looping over the object using it's keyset.
rB = ResourceBundle.getBundle("messages", new Locale(localeString));
Map<String, String> msgs = new HashMap<>();
for(String messageKey : rB.keySet()){
msgs.put(messageKey, rB.getString(messageKey));
}
Q1 : Is there any better/more elegant way to solve this?
Q2 : What is the reason for the authors to not allow for accessing all properties from a file ?