Multi language implementation

21 views
Skip to first unread message

Michal

unread,
Apr 14, 2009, 8:14:05 AM4/14/09
to nhusers
Hello all,

I am completely new to hibernate and would be interested in the
solution to the following problem:

My application needs to support data in multiple languages. E.g A
product contains a title which can be stored in English, German,
Spanish, etc.

Could you tell me the best practice of how ..

A) would you store the details in the database (consider an
application with several business objects which contain several
translated properties)

B) would you model your classes so that it allows me to load an
instance in a given language (e.g. determined from
Threading.Culture, ...)

Thanks a lot for any advise.

Yaojian

unread,
Apr 14, 2009, 9:14:07 AM4/14/09
to nhu...@googlegroups.com
I wonder there is no direct support for multi-languaged data in NHibernate.

Suppose you have a Customer class, and the Customer.Name and Customer.Address properties should be multi-languaged.
The solution depends on whether the user interface layer expose the Name/Address in one language only or all posible language values at a given time.

A)   Store Name for all languages in one database field and map them as NHibernate component
B)   Store Name for one language as a database field:
    B.1) Customer (ID, Address_en, Address_german, ...)  and map all these Address_XX columns in one NHIbernate dynamic-component
    B.2) Create a table for Customer and another table for its language resources in Customer, such as (CustomerID, LanguageID, Address, ..)
           The mapping is the same as B.1
    B.3) Create a table for Customer without Name/Address, and create a resource table for storing for all language resources for all entities, such as Resources(ResourceTypeID, OwnerID, LanguageID, Resource), of which the ResourceTypeID specifies if a resouce represents Customer.Name or Customer.Address, and the OwnerID specifies the CustomerID that owns this resource.
            You can map the Resources as  B.3.1) a standalone NHibernate entity or an manage it yourself, or B.3.2) map the Resources as a family of classes, each class for a kind of ResourceTypeID.

I prefer B.3.1 as it is simpler and does not require much NHibernate knowledge:-)

NHibernate have a "filter" feature may helps if you want to expose the name/address in one language only. It may be used to filter the Resources with the current LanguageID.

Fabio Maulo

unread,
Apr 14, 2009, 9:36:46 AM4/14/09
to nhu...@googlegroups.com

cws

unread,
Apr 14, 2009, 8:32:20 AM4/14/09
to nhusers
Hi!

Wouldn't you use resources for that?

Michal

unread,
Apr 15, 2009, 3:40:06 AM4/15/09
to nhusers


On Apr 14, 7:32 pm, cws <cw.stenb...@gmail.com> wrote:
> Hi!
>
> Wouldn't you use resources for that?

so far i thought resources are only for translations of messages
within the "code".
Do you have a code sample?

Michal

unread,
Apr 15, 2009, 3:42:47 AM4/15/09
to nhusers


On Apr 14, 8:14 pm, Yaojian <sky...@gmail.com> wrote:
> I wonder there is no direct support for multi-languaged data in NHibernate.
>
> Suppose you have a Customer class, and the Customer.Name and
> Customer.Address properties should be multi-languaged.
> The solution depends on whether the user interface layer expose the
> Name/Address in one language only or all posible language values at a given
> time.

the UI layer would expose it in one language at a time .. just for
administration it would require to see all ..

>
> A)   Store Name for all languages in one database field and map them as
> NHibernate component
> B)   Store Name for one language as a database field:
>     B.1) Customer (ID, Address_en, Address_german, ...)  and map all these
> Address_XX columns in one NHIbernate dynamic-component
>     B.2) Create a table for Customer and another table for its language
> resources in Customer, such as (CustomerID, LanguageID, Address, ..)
>            The mapping is the same as B.1
>     B.3) Create a table for Customer without Name/Address, and create a
> resource table for storing for all language resources for all entities, such
> as Resources(ResourceTypeID, OwnerID, LanguageID, Resource), of which the
> ResourceTypeID specifies if a resouce represents Customer.Name or
> Customer.Address, and the OwnerID specifies the CustomerID that owns this
> resource.
>             You can map the Resources as  B.3.1) a standalone NHibernate
> entity or an manage it yourself, or B.3.2) map the Resources as a family of
> classes, each class for a kind of ResourceTypeID.
>
> I prefer B.3.1 as it is simpler and does not require much NHibernate
> knowledge:-)
>
> NHibernate have a "filter" feature may helps if you want to expose the
> name/address in one language only. It may be used to filter the Resources
> with the current LanguageID.

aight. Guess i have a clue what you are talking about. B 3.1 sounds
good to me as well..

Michal Gabrukiewicz

unread,
Jun 24, 2009, 12:59:10 PM6/24/09
to nhu...@googlegroups.com
here is a detailed description of how i did solved the multi language problem:http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/
 
On 15 Apr., 14:42, Michal <mga...@gmail.com> wrote:
> On Apr 14, 8:14 pm, Yaojian <sky...@gmail.com> wrote:
>
> > I wonder there is no direct support formulti-languaged data in NHibernate.

>
> > Suppose you have a Customer class, and the Customer.Name and
> > Customer.Address properties should bemulti-languaged.
> > The solution depends on whether the user interface layer expose the
> > Name/Address in onelanguageonly or all posiblelanguagevalues at a given
> > time.
>
> the UI layer would expose it in onelanguageat a time .. just for

> administration it would require to see all ..
>
>
>
>
>
> > A)   Store Name for all languages in one database field and map them as
> > NHibernate component
> > B)   Store Name for onelanguageas a database field:

> >     B.1) Customer (ID, Address_en, Address_german, ...)  and map all these
> > Address_XX columns in one NHIbernate dynamic-component
> >     B.2) Create a table for Customer and another table for itslanguage
> > resources in Customer, such as (CustomerID, LanguageID, Address, ..)
> >            The mapping is the same as B.1
> >     B.3) Create a table for Customer without Name/Address, and create a
> > resource table for storing for alllanguageresources for all entities, such

> > as Resources(ResourceTypeID, OwnerID, LanguageID, Resource), of which the
> > ResourceTypeID specifies if a resouce represents Customer.Name or
> > Customer.Address, and the OwnerID specifies the CustomerID that owns this
> > resource.
> >             You can map the Resources as  B.3.1) a standalone NHibernate
> > entity or an manage it yourself, or B.3.2) map the Resources as a family of
> > classes, each class for a kind of ResourceTypeID.
>
> > I prefer B.3.1 as it is simpler and does not require much NHibernate
> > knowledge:-)
>
> > NHibernate have a "filter" feature may helps if you want to expose the
> > name/address in onelanguageonly. It may be used to filter the Resources

> > with the current LanguageID.
>
> aight. Guess i have a clue what you are talking about. B 3.1 sounds
> good to me as well..
>
>
>
> > On Tue, Apr 14, 2009 at 8:14 PM, Michal <mga...@gmail.com> wrote:
>
> > > Hello all,
>
> > > I am completely new to hibernate and would be interested in the
> > > solution to the following problem:
>
> > > My application needs to support data in multiple languages. E.g A
> > > product contains a title which can be stored in English, German,
> > > Spanish, etc.
>
> > > Could you tell me the best practice of how ..
>
> > > A) would you store the details in the database (consider an
> > > application with several business objects which contain several
> > > translated properties)
>
> > > B) would you model your classes so that it allows me to load an
> > > instance in a givenlanguage(e.g. determined from

> > > Threading.Culture, ...)
>
> > > Thanks a lot for any advise.



--
michal

Michal Gabrukiewicz

unread,
Jun 24, 2009, 12:59:10 PM6/24/09
to nhu...@googlegroups.com
here is a detailed description of how i did solved the multi language problem:http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/
 
On 15 Apr., 14:42, Michal <mga...@gmail.com> wrote:
> On Apr 14, 8:14 pm, Yaojian <sky...@gmail.com> wrote:
>
> > I wonder there is no direct support formulti-languaged data in NHibernate.

>
> > Suppose you have a Customer class, and the Customer.Name and
> > Customer.Address properties should bemulti-languaged.
> > The solution depends on whether the user interface layer expose the
> > Name/Address in onelanguageonly or all posiblelanguagevalues at a given
> > time.
>
> the UI layer would expose it in onelanguageat a time .. just for

> administration it would require to see all ..
>
>
>
>
>
> > A)   Store Name for all languages in one database field and map them as
> > NHibernate component
> > B)   Store Name for onelanguageas a database field:

> >     B.1) Customer (ID, Address_en, Address_german, ...)  and map all these
> > Address_XX columns in one NHIbernate dynamic-component
> >     B.2) Create a table for Customer and another table for itslanguage
> > resources in Customer, such as (CustomerID, LanguageID, Address, ..)
> >            The mapping is the same as B.1
> >     B.3) Create a table for Customer without Name/Address, and create a
> > resource table for storing for alllanguageresources for all entities, such

> > as Resources(ResourceTypeID, OwnerID, LanguageID, Resource), of which the
> > ResourceTypeID specifies if a resouce represents Customer.Name or
> > Customer.Address, and the OwnerID specifies the CustomerID that owns this
> > resource.
> >             You can map the Resources as  B.3.1) a standalone NHibernate
> > entity or an manage it yourself, or B.3.2) map the Resources as a family of
> > classes, each class for a kind of ResourceTypeID.
>
> > I prefer B.3.1 as it is simpler and does not require much NHibernate
> > knowledge:-)
>
> > NHibernate have a "filter" feature may helps if you want to expose the
> > name/address in onelanguageonly. It may be used to filter the Resources

> > with the current LanguageID.
>
> aight. Guess i have a clue what you are talking about. B 3.1 sounds
> good to me as well..
>
>
>
> > On Tue, Apr 14, 2009 at 8:14 PM, Michal <mga...@gmail.com> wrote:
>
> > > Hello all,
>
> > > I am completely new to hibernate and would be interested in the
> > > solution to the following problem:
>
> > > My application needs to support data in multiple languages. E.g A
> > > product contains a title which can be stored in English, German,
> > > Spanish, etc.
>
> > > Could you tell me the best practice of how ..
>
> > > A) would you store the details in the database (consider an
> > > application with several business objects which contain several
> > > translated properties)
>
> > > B) would you model your classes so that it allows me to load an
> > > instance in a givenlanguage(e.g. determined from

> > > Threading.Culture, ...)
>
> > > Thanks a lot for any advise.



--
michal

Fabio Maulo

unread,
Jun 24, 2009, 1:06:58 PM6/24/09
to nhu...@googlegroups.com
2009/6/24 Michal Gabrukiewicz <mga...@gmail.com>

here is a detailed description of how i did solved the multi language problem:http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/

Thanks Michal!!
Do you want share it in the NH-Forge "How to" wiki ?

If you need to upload a zip file you can do it in your own homepage inside NH-Forge.

Thanks again to share your solution.
--
Fabio Maulo

Michal Gabrukiewicz

unread,
Jun 24, 2009, 10:12:30 PM6/24/09
to nhu...@googlegroups.com
sure why not.
i guess i need some access to it ...

best regards
michal
--
michal

Dario Quintana

unread,
Jun 24, 2009, 10:34:07 PM6/24/09
to nhu...@googlegroups.com
The wiki is open for every registered user.


On Wed, Jun 24, 2009 at 11:12 PM, Michal Gabrukiewicz <mga...@gmail.com> wrote:
sure why not.
i guess i need some access to it ...

best regards
michal


--
Dario Quintana
http://darioquintana.com.ar

Fabio Maulo

unread,
Jun 29, 2009, 12:27:06 AM6/29/09
to nhu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages