You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Armin Waibel <ar...@apache.org> on 2007/05/05 20:14:35 UTC

Re: internationalization with OJB

Hi Ozkan,

sorry for the late reply. Last week I a had DSL malfunction caused by my 
Internet provider. It seems to be fixed (works again for 20 hours), but 
it could happen that I'm out of business again.

zkn wrote:
> Is internationalization possible with OJB?
> 

yep! why not?

> I'm not sure if the question is correct. I have to create a web 
> application that has to support multiple languages. I'm going to use 
> resource files for the messages.
> But are there any best practices for making databases with multi 
> language support and does OJB support one?

(nearly) All best practices of internationalization via databases should 
also be possible with OJB.

A popular way (don't know if this is the best way to do it ;-)) is to 
use a language identifier in the classes with multiple language support.
For example, class ProductGroup need support for multiple languages in 
field 'String name'. Add a INTEGER column "name_id" in table 
PRODUCT_GROUP and use a FieldConversion
http://db.apache.org/ojb/docu/guides/jdbc-types.html#The+Solution
in the mapping of field 'name' to transform the column 'name_id' to the 
language specific java-field 'name' in class ProductGroup.

Mapping ProductGroup:

....
<field-descriptor
   name="name"
   column="name_id"
   jdbc-type="INTEGER"
   conversion="my.LanguageConversion"
/>
...


public static class LanguageConversion implements FieldConversion
{
     public Object javaToSql(Object source) throws ConversionException
     {
         return Language.getId((String) source, User.getLanguage())
     }

     public Object sqlToJava(Object source) throws ConversionException
     {
         return Language.getName((Integer) source, User.getLanguage())
     }
}

In class Language the mapping of language identity to language string 
and vice versa is done. In class User the locale of the current user is 
managed.
Hope this simplified example can give you an impetus.

regards,
Armin

> 
> Thanks,
> Ozkan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org