<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://nhforge.org/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques.aspx</link><description>Quick starts, tutorials, code snippets, custom user types, application blocks and more...</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques.aspx</link><pubDate>Sat, 29 Oct 2011 01:07:45 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:73</guid><dc:creator>brendan2452</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Current revision posted to How to by brendan2452 on 28/10/2011 10:07:45 p.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: &lt;span style="text-decoration: line-through; color: red;"&gt;IUserType&lt;/span&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;,&lt;/span&gt; Filters&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUserType&lt;/span&gt;, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on a post in spanish on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a Fabio &lt;span style="text-decoration: line-through; color: red;"&gt;Maulo&lt;/span&gt;&lt;/a&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;`&lt;/span&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Maulo`s&lt;/span&gt; post called Localized Property with NHibernate, in which he discusses the use of the LocalizablePropertyType found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This&amp;nbsp;second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: Localizing NHibernate: Contextual Parameters by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: Create a multi languaged domain model with NHibernate and C# by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: Mapping translations in NHibernate by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: Localizable entities with Nhibernate part 1 (part 2 and part 3) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough&amp;nbsp; example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[howtonh:stuffynoseremedy.net/stuffy-nose-remedy/|stuffy&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;nose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;remedy]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using NHibernate.Search&amp;nbsp;and Lucene.NET using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in NHUsers discussion on the topic.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/13.aspx</link><pubDate>Fri, 28 Oct 2011 14:13:21 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:523</guid><dc:creator>John Davidson</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 13 posted to How to by John Davidson on 28/10/2011 11:13:21 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method 1: Using a custom IUserType&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;a href="http://www.casinomagic.co.uk/%20%20%20"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Best&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;Online&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;Casino&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Method 2: Using several tables&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This&amp;nbsp;second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.1&lt;/strong&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.2&lt;/strong&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.3&lt;/strong&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.4&lt;/strong&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough&amp;nbsp; example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp;and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/12.aspx</link><pubDate>Fri, 28 Oct 2011 13:56:54 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:522</guid><dc:creator>liliasmit</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 12 posted to How to by liliasmit on 28/10/2011 10:56:54 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database. &lt;a href="http://www.casinomagic.co.uk/%20%20%20"&gt;&lt;span style="background: SpringGreen;"&gt;Best&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Online&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Casino&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This&amp;nbsp;second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough&amp;nbsp; example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp;and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/11.aspx</link><pubDate>Wed, 06 Jul 2011 13:22:53 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:521</guid><dc:creator>John Davidson</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 11 posted to How to by John Davidson on 06/07/2011 10:22:53 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method 1: Using a custom IUserType&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Method 2: Using several tables&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This&lt;a href="http://www.regentmbaprojects.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;MBA&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;Project&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;reports&lt;/span&gt;&amp;nbsp;second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.1&lt;/strong&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.2&lt;/strong&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping&lt;a href="http://hfiainsurance.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;auto&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;insurance&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;quotes&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.3&lt;/strong&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.4&lt;/strong&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough&amp;nbsp; example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp;and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/10.aspx</link><pubDate>Wed, 06 Jul 2011 04:59:56 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:486</guid><dc:creator>MBA Project reports</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 10 posted to How to by MBA Project reports on 06/07/2011 01:59:56 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This &lt;a href="http://www.regentmbaprojects.com/"&gt;&lt;span style="background: SpringGreen;"&gt;MBA&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Project&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reports&lt;/span&gt;&lt;/a&gt; second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough&amp;nbsp; example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp;and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/9.aspx</link><pubDate>Fri, 01 Jul 2011 10:41:47 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:485</guid><dc:creator>John Davidson</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 9 posted to How to by John Davidson on 01/07/2011 07:41:47 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method 1: Using a custom IUserType&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Method 2: Using several tables&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.1&lt;/strong&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.2&lt;/strong&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.3&lt;/strong&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.4&lt;/strong&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp; &lt;a href="http://www.cjmdefense.com/dui-lawyer-huntington-beach"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;DUI&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;Lawyer&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;in&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;huntington&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;Beach&lt;/span&gt;&lt;/a&gt;&amp;nbsp;and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/8.aspx</link><pubDate>Fri, 01 Jul 2011 10:41:12 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:470</guid><dc:creator>John Davidson</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 8 posted to How to by John Davidson on 01/07/2011 07:41:12 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Method 1: Using a custom IUserType&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Mustuniversity&lt;/span&gt;&lt;/a&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;|&lt;/span&gt;
&lt;a href="http://www.aboutmustuniversity.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Must&lt;/span&gt;
&lt;span style="text-decoration: line-through; color: red;"&gt;University&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Must&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;University&lt;/span&gt;
&lt;span style="text-decoration: line-through; color: red;"&gt;Accredited&lt;/span&gt;&lt;/a&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;|&lt;/span&gt; &lt;a href="http://www.aboutmustuniversity.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Mustuniversity&lt;/span&gt;&lt;/a&gt;
 &lt;span style="text-decoration: line-through; color: red;"&gt;|&lt;/span&gt; &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;Must&lt;/span&gt;
&lt;span style="text-decoration: line-through; color: red;"&gt;University&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.hhgregg.com/ProductDetail.asp?productId=19569"&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;LCD&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;HDTV&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Method 2: Using several tables&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.1&lt;/strong&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.2&lt;/strong&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.3&lt;/strong&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proposal 2.4&lt;/strong&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp; &lt;a href="http://www.cjmdefense.com/dui-lawyer-huntington-beach"&gt;DUI Lawyer in huntington Beach&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/7.aspx</link><pubDate>Fri, 01 Jul 2011 07:43:11 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:469</guid><dc:creator>Criminal Defense Lawyer in Long Beach</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 7 posted to How to by Criminal Defense Lawyer in Long Beach on 01/07/2011 04:43:11 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns. &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;Mustuniversity&lt;/a&gt; |
&lt;a href="http://www.aboutmustuniversity.com/"&gt;Must
University&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database. &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;Must University
Accredited&lt;/a&gt; | &lt;a href="http://www.aboutmustuniversity.com/"&gt;Mustuniversity&lt;/a&gt;
 | &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;Must
University&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.hhgregg.com/ProductDetail.asp?productId=19569"&gt;LCD HDTV&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt;&amp;nbsp; &lt;a href="http://www.cjmdefense.com/dui-lawyer-huntington-beach"&gt;&lt;span style="background: SpringGreen;"&gt;DUI&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Lawyer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;huntington&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Beach&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/6.aspx</link><pubDate>Wed, 30 Mar 2011 11:47:46 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:468</guid><dc:creator>markweee</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 6 posted to How to by markweee on 30/03/2011 08:47:46 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns. &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="background: SpringGreen;"&gt;Mustuniversity&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;|&lt;/span&gt;
&lt;a href="http://www.aboutmustuniversity.com/"&gt;&lt;span style="background: SpringGreen;"&gt;Must&lt;/span&gt;
&lt;span style="background: SpringGreen;"&gt;University&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database. &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="background: SpringGreen;"&gt;Must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;University&lt;/span&gt;
&lt;span style="background: SpringGreen;"&gt;Accredited&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;|&lt;/span&gt; &lt;a href="http://www.aboutmustuniversity.com/"&gt;&lt;span style="background: SpringGreen;"&gt;Mustuniversity&lt;/span&gt;&lt;/a&gt;
 &lt;span style="background: SpringGreen;"&gt;|&lt;/span&gt; &lt;a href="http://www.mustuniversityaccreditation.com/"&gt;&lt;span style="background: SpringGreen;"&gt;Must&lt;/span&gt;
&lt;span style="background: SpringGreen;"&gt;University&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.hhgregg.com/ProductDetail.asp?productId=19569"&gt;LCD HDTV&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/5.aspx</link><pubDate>Fri, 24 Sep 2010 17:18:41 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:384</guid><dc:creator>mikeon098</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 5 posted to How to by mikeon098 on 24/09/2010 02:18:41 p.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.hhgregg.com/ProductDetail.asp?productId=19569"&gt;LCD HDTV&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://hfiainsurance.com/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/4.aspx</link><pubDate>Thu, 26 Aug 2010 12:35:37 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:348</guid><dc:creator>tcook23</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 4 posted to How to by tcook23 on 26/08/2010 09:35:37 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.hhgregg.com/ProductDetail.asp?productId=19569"&gt;&lt;span style="background: SpringGreen;"&gt;LCD&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;HDTV&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://zolpo.com/auto-insurance/"&gt;auto insurance quotes&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/3.aspx</link><pubDate>Fri, 28 May 2010 12:41:41 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:343</guid><dc:creator>mike3050</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 3 posted to How to by mike3050 on 28/05/2010 09:41:41 a.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary (internally) but we choose to expose it as a String developing the getter (in Fabio&amp;#39;s post) to make it easier for the user.&lt;/p&gt;
&lt;p&gt;Alternatively, you can create your our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method. This, as well, can be exposed as a string through the proper getter.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping &lt;a href="http://zolpo.com/auto-insurance/"&gt;&lt;span style="background: SpringGreen;"&gt;auto&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;insurance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;quotes&lt;/span&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/2.aspx</link><pubDate>Tue, 16 Mar 2010 15:27:42 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:317</guid><dc:creator>Marc Climent</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 2 posted to How to by Marc Climent on 16/03/2010 12:27:42 p.m.&lt;br /&gt;
&lt;h2&gt;Localization techniques&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: IUserType, Filters, l18n, localization, property&lt;/div&gt;

&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;internally)&lt;/span&gt; but we &lt;span style="background: SpringGreen;"&gt;choose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;String&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;developing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;getter&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Fabio&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;post&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;easier&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;user&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Alternatively&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; can create &lt;span style="background: SpringGreen;"&gt;your&lt;/span&gt; our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;well&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;exposed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;through&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;proper&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;getter&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;li&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;The&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;entity&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;property&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;can&lt;/span&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;t&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;be&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;a&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;string&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item><item><title>Localization techniques</title><link>http://nhforge.org/wikis/howtonh/localization-techniques/revision/1.aspx</link><pubDate>Tue, 16 Mar 2010 12:18:25 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:312</guid><dc:creator>Marc Climent</dc:creator><comments>http://nhforge.org/wikis/howtonh/localization-techniques/comments.aspx</comments><description>Revision 1 posted to How to by Marc Climent on 16/03/2010 09:18:25 a.m.&lt;br /&gt;
&lt;p&gt;This page is a summary of the two main different approaches found all around the web on Property Localization using NHibernate, based on &lt;a href="http://codelog.climens.net/2010/03/16/nhibernate-y-localizacion/"&gt;a post in spanish&lt;/a&gt; on my own blog.&lt;/p&gt;
&lt;p&gt;There are roughly two main paths&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Method 1: Using a custom IUserType&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This method is exposed thoroughly in a &lt;a href="/members/fabiomaulo/default.aspx"&gt;Fabio Maulo&lt;/a&gt;`s post called Localized Property with NHibernate, in which he discusses the use of the &lt;a href="http://code.google.com/p/unhaddins/source/browse/trunk/uNhAddIns/uNhAddIns/UserTypes/LocalizablePropertyType.cs"&gt;LocalizablePropertyType&lt;/a&gt; found in uNhAddIns.&lt;/p&gt;
&lt;p&gt;It is based on implementing IUserType, providing methods to serialize and deserialize the property. This way, we make use of NHibernate extensibility to provide a seamless mechanism to store and retrieve the property in a field of the database.&lt;/p&gt;
&lt;p&gt;In the example, the property is a Dictionary but we can create our own class to contain all the translations and ease the addition and removal of them as well as properties to have quick access to the current localization string based on &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt;. In some of the proposals in the second method discussed there are examples of such classes that can be easily adapted to this method.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple and easy&lt;/li&gt;
&lt;li&gt;Data stored in the same table as the entity&lt;/li&gt;
&lt;li&gt;Fairly transparent, specially if a custom object is used to simplify the access to the translations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The value of the field is not understandable by the DBMS (no indexing, sorting or whatever)&lt;/li&gt;
&lt;li&gt;The entity property can&amp;#39;t be a string&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Method 2: Using several tables&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This second method has many variants, but all of them use one or more tables to store the translations, making them visible to the DBMS.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.1&lt;/b&gt;: &lt;a href="http://ayende.com/Blog/archive/2006/12/26/localizingnhibernatecontextualparameters.aspx"&gt;Localizing NHibernate: Contextual Parameters&lt;/a&gt; by Ayende&lt;/p&gt;
&lt;p&gt;This is an interesting approach, quite simple in explanation but uses a couple of advanced NHibernate features such as formulas and filters. The advantage is that the property of the entity is a simple string and the selection of the language to load is made through the formula based on a session parameter.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.2&lt;/b&gt;: &lt;a href="http://www.webdevbros.net/2009/06/24/create-a-multi-languaged-domain-model-with-nhibernate-and-c/"&gt;Create a multi languaged domain model with NHibernate and C#&lt;/a&gt; by Michal @ WebDevBros&lt;/p&gt;
&lt;p&gt;This one uses a nice crafted class to store and retrieve localization information and a couple of tables, one containing the dictionaries that create the relationship between the entity and the translations, that are accessed via a &amp;lt;map&amp;gt; in the mapping. (NOTE: I have not tested it, and he says that you can map several properties in the same entity with this method but not with the provided mapping)&lt;/p&gt;
&lt;p&gt;The class called PhraseDictionary can be easily used through a IUserType with the first method.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.3&lt;/b&gt;: &lt;a href="http://www.siimviikman.com/2010/02/24/mapping-translations-in-nhibernate/"&gt;Mapping translations in NHibernate&lt;/a&gt; by Siim Viikman&lt;/p&gt;
&lt;p&gt;The method proposed here is very similar to the former one, in this case using three tables, but that&amp;#39;s up to you. It explains how to do the mapping using an Id different from the PK (which can&amp;#39;t be done at this moment using Fluent NHibernate, just in case you want to).&lt;/p&gt;
&lt;p&gt;The PhraseDictionary has been replaced by the Translation class, but essentially are the same, holders of the translation dictionary. Can be adapted as well to use it with method 1.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposal 2.4&lt;/b&gt;: &lt;a href="http://www.codewrecks.com/blog/index.php?p=41"&gt;Localizable entities with Nhibernate part 1&lt;/a&gt; (&lt;a href="http://www.codewrecks.com/blog/index.php?p=42"&gt;part 2&lt;/a&gt; and &lt;a href="http://www.codewrecks.com/blog/index.php/2007/05/23/localize-entity-with-nhibernate-part-3/"&gt;part 3&lt;/a&gt;) by Alkampfer&lt;/p&gt;
&lt;p&gt;A very thorough example. It maps only one property per entity, simplifying the mappings and the table structure and can be more than enough for many solutions. It discusses a lot about a Registry object to hold the current locale, but you can change that to rely in &lt;i&gt;Thread.CurrentThread.CurrentCulture&lt;/i&gt; and simplify a little bit.&lt;/p&gt;
&lt;p&gt;Pros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DBMS-aware solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More complex mappings&lt;/li&gt;
&lt;li&gt;More complex data structure&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Conclusions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Localization is painful in most scenarios and some guidelines can be followed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you don&amp;#39;t really need that a property is localizable, don&amp;#39;t make it localizable. Ok, in most cases is not your decision. If you have choice, think it twice or thrice before making a property localizable.&lt;/li&gt;
&lt;li&gt;If you don&amp;#39;t need to use DBMS capabilities on the field (such as sorting), go for the first method, it&amp;#39;s easy to to the IUserType and the mappings and as well as the serialization is well tested won&amp;#39;t give much trouble&lt;/li&gt;
&lt;li&gt;If you need DBMS capabilities, in most cases only some properties will need this, so instead of embracing blindly the second method, think if a mixed solution is not simpler and better for you. (Was in my case)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note, if you need to index the property, think of using &lt;a href="http://darioquintana.com.ar/blogging/2007/12/09/nhibernate-search/"&gt;NHibernate.Search&lt;/a&gt; and &lt;a href="http://lucene.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; using method 1 and a custom Bridge implementation to store the localizations in the index.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all that participated in &lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b099f9f4a10a08f6"&gt;NHUsers discussion&lt;/a&gt; on the topic.&lt;/p&gt;</description></item></channel></rss>