Is there an easy way to do the following, using the Play! framework and hibernate?
I have a class Article with generic data like pubDate, author etc. etc.
In the class there are two fields, title and content, which needs however be provided in different languages. All the other data, inclusing the id should be the same.
The server side of the system will select according to the settings of the client which title/content to push out, either the default language or the language of preference when available. Beacuse of the synchronisation it is important to keep the article id the same for all linked languages.
Currently I have the content and the title in the class, and am wondering if I should either subclass the baseclass which has all the basic info and add the content/title that way, our leave the content/title of the default language in the baseclass and optionally add the content/title of additinoal languages as an seperate class (and on pushing it to the client replace it the content transciently in the baseclass if required).
What would be the best way to approach this problem?
I wouldn’t subclass, because language preference is a rendering issue. There’s no different behavior by
Articlejust because the content is in a different language.I’d have the
Articleclass include title, content, and language. The primary key would now be article id and language. When a user asked for a particular title I’d query for it using the article id and either their language preference or the default if none was provided.