full globalization for default validation messages #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds full globalization for all default validation messages and solves the following issues
This is fully compatible with old cbvalidation versions, just one potential problem if you are using unknown locales in your app. Which can be adressed. See my PR for cbi18n
The changes:
property name="resourceService" inject="ResourceService@cbi18n";
and all validation error messages have been replaced by resourceService.getResource("default.ValidationType@cbvalidation"), in some cases some values are added to the resources.
I want to add also a smarter way to handle custom messages in Internationalization.
such as {ObjectName}.{Field}.{ConstraintType}}
This can only be added in a DEFAULT resource now, and I want to have them to be available in any resource alias I want. Can easily be solved by adding another setting called resourceAliasName (or something simular) which can default to 'default' which is the current situation, 'cbvalidation' which is were all default messages are, or something new. Makes it very flexible, and keeps your validation messages in one place.
There's one problem right now: if you add an unknown locale cbvalidation will fail, because the locale is not there. This is because cbi18n ALWAYS needs a valid locale.
I think providing the most used languages shouldn't be a problem, such as en, es, de, fr, nl.
But most locales have country variants such as en_US, en_UK, nl_NL, nl_BE etcetera. If we provide them all it adds up and we still have no default.
By a simple modification in cbi18n this can be solved. Make the locale lookup hierarchical.
So try to find nl_BE. If it is not there try to find nl (so without the country destination) and if still not found try the default locale.
So let's say cbvalidation_nl_BE.properties, followed by cbvalidation_nl.properties, followed by cbvalidatiion.properties. Which is actually how this is meant in java locales, but cbi18n doesn't implement it yet.
We can make this behaviour optional (so no changes to old cbi18n) but is is way more flexible and if we specify lookupParentResource=true (or something simular) our cbvalidation will never fail.