Approach to localization mapping

18 views
Skip to first unread message

Marc Climent

unread,
Mar 10, 2010, 4:47:05 AM3/10/10
to Fluent NHibernate
I'm trying to figure out how to implement localization of some fields
using tables (right now I'm using a Custom Type and works well until I
need sorting, which is quite slow if there are many rows).

I have found a lot of articles but most of them deal with only one
localizable property, which is not my case. I'm sure there must be a
solution, maybe I'm not on the right track.

I have a class like this, for example:

class Document {
public virtual Guid Id { get; set; }
public virtual string Code { get; set; }
public virtual LocalizableString Title { get; set; }
public virtual LocalizableString Description { get; set; }

}

LocalizableString is not really a string, but hides a dictionary with
the several translations available for that specific property. This
LocalizableString is not as well a Dictionary, but it could be and I
could add a couple of methods to simplify the use of the
localizations.

The thing is how to relate these properties with the table that
contains the translation for each field and how to map that using
FluentNH.

For example, with two tables, where Title_Id and Description_Id are
related with Resource_Id:
[Documents] - [Id] [Code] [Title_Id] [Description_Id]
[Localizations] - [Resource_Id] [LCID] [Value]

Or maybe three tables, where the relationship between the entity/
property is done through the Entity_Id and the Entity_Field (¿dynamic
components?):
[Documents] - [Id] [Code]
[Dictionaries] - [Dict_Id] [Entity_Id] [Entity_Field]
[Localizations] - [Dict_Id] [LCID] [Value]

I don't really know how to map this, any clue is welcome, maybe the
whole approach is too complex.

These are the articles I've found on the subject:
http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/
http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/
http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/comment-page-1/

Asbjørn Ulsberg

unread,
May 11, 2010, 4:46:52 PM5/11/10
to Fluent NHibernate, Marc Climent
On Wed, 10 Mar 2010 10:47:05 +0100, Marc Climent <m.cl...@adapting.com>
wrote:

> class Document {
> public virtual Guid Id { get; set; }
> public virtual string Code { get; set; }
> public virtual LocalizableString Title { get; set; }
> public virtual LocalizableString Description { get; set; }
> }

Seems like a regular many-to-one relation, only with an IDictionary
instead of an ISet or IList in the many-end. I'd implement this as such:

protected virtual IDictionary<string, string> TitleDictionary { get; set; }

public virtual string Title
{
get { return TitleDictionary["en-GB"]; }
}

where "en-GB" of course needs to be dynamically looked up somewhere, but I
hope you get the idea. Notice how the dictionary is protected and the
string public. That way you can hide away the gritty details of the
dictionary lookup within the bowels of your class and not expose it to the
world.

The way to map the dictioanry is with the .AsMap() method. Take a look
here for more details:

http://stackoverflow.com/questions/1335859/fluent-nhibernate-mapping

--
Asbjørn Ulsberg -=|=- asb...@ulsberg.no
«He's a loathsome offensive brute, yet I can't look away»

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply all
Reply to author
Forward
0 new messages