Nov 16th, 2006, 11:19 PM
i18n and the database, multiLocale object, AOP proxy?
I am not sure if this is the right place to discuss this since it is kind of AOP related, but I'll give it a try anyway.
We have a multi language web application. It is using Hibernate for the mapping with the db and Spring to manage it.
Our database design is the following: any language sensitive entitiy X has a dependent entity (let's call it Xdetail) containing a record per language supported in the application. (I wish I'd be an expert in ASCII art and could draw the model... ). It is arguably the most flexible design, especially if you plan on supporting more languages in the future. It's also a pretty cumbersome one to work with.
As for the Java layer, those language dependent entities are mapped to business object like this. object X has a map of Xdetail object indexed by Locale. (Map<Locale, XDetail>). This is pretty neat but not easy to play with.
To access the name property of a language sensitive X object, you'd do the following: X.getXDetail().get(Locale.ENGLISH).getName(). I don't even want to mention creation of such an object...
Nevertheless, I still quite like the database design here. And I don't see any better mapping than this Map. So what can I do to simplify language sensitive object access?
My idea would be to create a proxy that would use the session or database stored User Locale preference to return or set the right language detail of a property upon access to a getter/setter method.
AOP seems particularly adapted for that matter. I'm only a novice in manipulating the concepts of Advice and Pointcut and particularly as for their implementation in Spring.
What I imagine is the following:
A proxy for any language sensitive Detail object would need to be dynamically generated. Every call to 'get*' and 'set*' on this proxy would be resolved through a Locale preference (say from Session) to the appropriate Detail instance.
My question would be am I dreaming here or something like this is really possible? That would avoid manually creating a Proxy class for each of those language sensitive objects.
And what would be a possible implementation using Spring AOP???