Loading more messages.properties files at runtime

Hi all,

I would like to load additional messages.properties files at runtime, from a configuration folder on the disk basically. We can assume that this configuration folder is somewhere within the OpenMRS folder. Is that possible, and if so, how? Could anyone point me to the relevant classes to achieve this?

Thanks in advance.

1 Like

You would have to add the location to the basenames array in the MutableResourceBundleMessageSource class, I believe in the past you said that you are changing the core code in your branch/fork, if yes, you could actually just add the location to the basenames list of the mutableResourceBundleMessageSource bean in the applicationContext-service.xml file.

Thanks @wyclif, however no we don’t intend to fork the Core. However you can assume that we are on Core 2.x if that makes things easier.

Can a custom module do what you suggested?

Core already allows modules to add their message resources, so why don’t you just add your messages to the custom module instead?

We precisely would like to avoid that since we intend to keep a certain number of metadata (such as some very specific translation dictionaries) outside of the packaging of modules. If that’s possible of course. A little bit on the model of Bahmni Config for Bahmni EMR, but this time for OpenMRS backend configuration.

We are leaning towards having a generic initializer module that can provide the OpenMRS instance with additional translations based on what’s being provided in a configuration folder.

Possible in your opinion?

I still think you could do that from a module, possibly as part of the build process to fetch the messages from the ‘centralized’ location and include them in the modules’ message.properties file.

That would require to rebuild the module for a specific change in configuration, which is exactly what we hope to avoid.

Is there a way to load such .properties files at runtime through a module’s activator (for instance)?

@mksd, the same principle that you applied to get the messages working in the unit test can be applied to load messages from a configuration location on disk. This is what we implemented in the custommessage module (though in that case, the messages were put in the database, the location could be anywhere).

So, in your module, add a custom message source, and have this load in messages from a config location. You’ll need to build this feature once, but it will allow for the messages themselves to be added and changed without code builds or deployments.


Yes sure, this worked like a charm within unit tests. I was wondering if that would be safe for in app production use, but hopefully it is. I will give it a try.

@mksd just in case you had not seen this: https://wiki.openmrs.org/display/docs/Custom+Messages+Module