A Curious Mind
#tastic

A multi-lingual domain

Thursday, August 14, 2008 6:37 PM

I am working on domain where I need to support the ability to translate content. Such as a product description. I am imagining that the domain model might look something like:

product.Description = "Widget";
product.Translation[Language.English].Description = "Tegdiw";

or

product.Description = "widget";
product.Description[Language.English] = "tegdiw";

or

IProduct product = repository.Get(1, English);
product.Description = "wow";
IProduct productZh = repository.Get(1, Chinese);
productZh.Description = "waw";

Of the three I have presented here, I think I like number one the best. I would say that I like it the most because I have done this model before and it seemed to work well, I am just wondering how much I really care that it forces me to have 2 tables per entity that I want translations for (Product and ProductTranslations). Really that's not that bad I guess. Anyways, I wanted to put my thoughts out there to see if anyone else had some better ideas. :)


Feedback

# re: A multi-lingual domain

Try this approach:
http://www.ayende.com/Blog/archive/2006/12/26/7001.aspx
8/15/2008 9:17 AM | Ayende Rahien

# re: A multi-lingual domain

I think you could have two tables to support all of your entities, String(Id, Value) and Translation(Id, StringId, LCID, Value).

If you are using NHibernate I recall Oren had some posts about transparently retrieving the correctly translated string based on the Thread.CurrentCulture. e.g. NHibernate would retrieve product.Description by filtering the Translation table for the proper value. 8/15/2008 9:59 AM | Bill Pierce

# re: A multi-lingual domain

Have to say I third Oren's solution. 8/19/2008 7:41 PM | Robz

# re: A multi-lingual domain

My problem with the oren solution is that I have some 30 translatable properties to manage, which would be a bit of a bear, and I suspect that one query with 30 sub-queries would be a bit overkill. I will detail this out a bit more in the near future. 8/19/2008 8:11 PM | Dru

Comments have been closed on this topic.