Reputation: 209
I am trying to override the main messages.properties file during runtime. My current task requires me to package application based on a product brand. For eg, if i pass a argument like "grails dev run-app -Dbrand=a", i should be able to change the messages in .properties file based on the brand.
Another requirement is that I need have one master .properties file which contains all the messages and I want to create a seperate folder to store the messages based on brand. For eg, my master .properties file will contain A,B,C,D and my brand .properties file will be a subset of master which will only contain A. (Th message string for A in master will definitely be different than message string in .properties file present under the brand folder). For eg, A.productName in .properties file for master could be "hello" and A.product name in .properties file could be "world".
When I do run-app with brand=a as argument, I need to be able to laod the A.product name from the .properties file under brand folder without disturbing the current state of the master .properties file.(This is so that changes do show up in git).
I looked at some approaches and the only good solution I found required getting messages from DB which I dont want to do. I want a way to override using some grails configuration or event listener.
I am assuming there needs to be a way to override the messages in the memory during run-time in grails.
Hope, my I asked my question in detail.
Please help, I am really new to grails.
Upvotes: 0
Views: 508
Reputation: 3124
I think you should look at how Localizations plugin handles this. It implements
org.springframework.context.support.AbstractMessageSource
It looks up the original message source from properties, if it is not found in a database table. Sounds like you want to archive some of the same functionality.
Grails in it self uses either
org.codehaus.groovy.grails.context.support.ReloadableResourceBundleMessageSource
or
org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource
I have not looked into wich of them is injected into the artefacts in the application.
Upvotes: 1