Background
We are migrating a legacy database that have the labels of fields internacionalized in the database. We still use the messages.properties for some static resouces like css classes (names). The table looks like:
ITEMS
-------------------------------------------
code number(3) not null PK
language_code number(3) not null PK
label varchar2(90) not null
hint varchar2(250) not null
help varchar2(4000)
label_client varchar2(90) not null
hint_client varchar2(250) not null
help_client varchar2(4000)
For the html components we just look for the item in this table, setting his label (custom TagLib), and this works well. Note that we also give the opportunity to the client modify some label (the *_client fields).
The Problem
By default, Grails will try to look in messages.properties with the suffix .label to use in the validation error message. For example (Person.name.label=name):
Property name must not be blank.
If my item in the database have the label Name of Person, in validations this will be inconsistent as the label of the input differs.
We cannot synchronize the items with the .properties because the client can change them. So the solution is to, somehow, modify the Grails validation messages to return the content of the database.
Is this possible? How can I, just for validation messages, get from the database instead of properties?
This blog post suggests you can do it by implementing your own
messageSourceSpring bean and registering it inresources.groovy. It dates from 2010 but still worth a try.