views:

306

answers:

1

We are trying to design a site that will support multilingual data and we use asp.net and nhibernate for O/R mapping. After some googling we decided that for us its best to create the entity classes containing all fields we need for supporting the default (english) language and for each multilingual class we would create a new class containing only the multilingual fields plus the id of the main (english) class and the language Id. For example a simple "product" class we could have the fields :

product

int ID
string DescriptionInEnglish
string FullDescriptionInEnglish
decimal price

and a second class "product_Lang" containing

product_Lang

int Product_ID
int Language_ID
string Description
string FullDescription

then for being able to load a product in any language we could add a product_Lang property called lang on the products and for easy binding we could have two read only properties like that :

string DescriptionToBind
{
  get
  {
    if (lang != null)
       return this.lang.Description;
    else
       return this.DescriptionInEnglish;
  }
}

string FullDescriptionToBind
{
  get
  {
    if (lang != null)
       return this.lang.FullDescription;
    else
       return this.FullDescriptionInEnglish;
  }
}

for loading some products we can use some methods on the ProductRpository like that :

 Product GetProductByID(int ID);
 Product GetProductbyID_ML(int ID, int Language_ID);

and for loading some collections

 IList<Product> GetAllProducts();
 IList<Product> GetAllProducts_ML(Language_ID);

The problem is how to map the Lang property inside the product class in nhibernate. It may be easy but I cannot figure out. Its not one-to-one because in english lang is optional. I thought about one-to-many so i load a list of all but i think its not fair to load all languages because i need only one.

Any help ? or any other suggestions will still give fair performance ?

A: 

I have written a detailed article about multi language implementation with ASP.NET and NHibernate.

Check Create a multi languaged domain model with NHibernate and C#

Michal
If I got it right you create a PhraseDictionary (to hold the languages) for every multilingual field in your business class. So for ten multilingual fields on a class we got ten PhraseDictionaries bound. Surely that is the best solution from the OO point of view but how about performance ?
George Statis
Did not do any specific benchmarking but so far have not experienced any bottlenecks using this approach.
Michal