Search code examples
grailsgrails-plugin

Access process i18n property files before compilation


I have a following situation: in some of my i18n property files there are properties containing a special word:

  • prop.example=specialword just for example
  • prop.test=just for test specialword

I want to have a possibility of having a property somewhere in my Config.groovy that would contain a specific value for this specialword so that if I specify:

specialword=Value of special word

in a Config.groovy then I want my i18n properties to be resolved like:

  • prop.example=Value of special word just for example
  • prop.test=just for test Value of special word

for that purpose, when building the project, I want to access property files in order to look for occurences of specialword and to replace them with value of specialwordvalue from Config.groovy.

Is that possible somehow? Perhaps, someone faced similar situation? I would really appreciate any help. Thanks, Cheers


Solution

  • Instead of trying to change the way the properties are compiled, you would be better off passing the special value as an argument to your message code (as discussed in the comments to your question).

    For instance: <g:message code="my.key.code" args="[someVariableWithAValueFromConfig]" />

    If your message code doesn't use the argument it will simply be ignored. This seems like the best approach to the problem you are trying to solve.