How would you build your domain objects and create its respective NHibernate mapping files for a multi language application. The UI part is stored in resource files but user data needs to go into the database.
I want to do the following:
Product p = DALProduct.getByID(2)
p.name //results in the language of the current UICulture
I have found the following article which is really close: http://ayende.com/Blog/archive/2006/12/26/LocalizingNHibernateContextualParameters.aspx As I am new to NHibernate I am not sure if that will perfectly work for enterprise solutions.
Do you have other suggestions? How do you solve such scenario?
It should be flexible to:
Ayendes post is a great start how it should be designed.
It will perfectly work for enterprise solutions. The names in a separate table is like any other list of values. The special thing is, that it is filtered in the mapping.
Edit - Options:
Use another entity to edit the data
There is Product entity that has all the names as list. LocalizedProduct has only the current languages name.
Get the filtered entity
If you have many references to Product, it is probably not so nice to have two classes, because you don't know which class the reference should have.
Use the same entity for editing and displaying
class Product
{
string LocalizedName
{
get { return AllProductNames[Thread.CurrentThread.CurrentCulture.LCID]; }
}
IDictionary<int, string> AllProductNames { get; private set; }
}
There are properties for a localized product name (get) and all product names.
To be honest, I would choose a option that dies not need filters in the mapping files. Filters belong to queries where they are more maintainable.