1- =========================
21Xtensive.Orm.Localization
32=========================
43
@@ -9,35 +8,14 @@ This implies that localizable resources are a part of domain model so they are s
98
109Prerequisites
1110-------------
12- DataObjects.Net Core 0.1 or later (http://dataobjects.net)
11+ DataObjects.Net 6.0.x or later (http://dataobjects.net )
1312
1413Implementation
1514--------------
16- 1. Add reference to Xtensive.Orm.Localization assembly
17- 2. Include types from Xtensive.Orm.Localization assembly into the domain:
18-
19- <Xtensive.Orm>
20- <domains>
21- <domain ... >
22- <types>
23- <add assembly="your assembly"/>
24- <add assembly="Xtensive.Orm.Localization"/>
25- </types>
26- </domain>
27- </domains>
28- </Xtensive.Orm>
29-
30- 2.1 Optionally add default localization configuration
31- <configSections>
32- <section name="Xtensive.Orm.Localization" type="Xtensive.Orm.Localization.Configuration.ConfigurationSection, Xtensive.Orm.Localization"/>
33- </configSections>
34-
35- <Xtensive.Orm.Localization>
36- <defaultCulture name="es-ES"/>
37- </Xtensive.Orm.Localization>
38-
39- 3. Implement ILocalizable<TLocalization> on your localizable entities, e.g.:
4015
16+ Implement ILocalizable<TLocalization > on your localizable entities, e.g.:
17+
18+ ``` csharp
4119 [HierarchyRoot ]
4220 public class Page : Entity , ILocalizable <PageLocalization >
4321 {
@@ -56,9 +34,11 @@ Implementation
5634
5735 public Page (Session session ) : base (session ) {}
5836 }
37+ ```
5938
60- 4. Define corresponding localizations, e.g.:
39+ Define corresponding localizations, e.g.:
6140
41+ ``` csharp
6242 [HierarchyRoot ]
6343 public class PageLocalization : Localization <Page >
6444 {
@@ -68,42 +48,53 @@ Implementation
6848 public PageLocalization (Session session , CultureInfo culture , Page target )
6949 : base (session , culture , target ) {}
7050 }
51+ ```
52+
53+ Examples of usage
54+ -----------------
7155
72- Demo
73- ----
74- 1. Access localizable properties as regular ones, e.g.:
56+ ** Example #1 ** . Access localizable properties as regular ones, e.g.:
7557
58+ ``` csharp
7659 page .Title = " Welcome" ;
7760 string title = page .Title ;
61+ ```
7862
79- 2 . Mass editing of localizable properties:
63+ ** Example # 2 ** . Mass editing of localizable properties:
8064
65+ ``` csharp
8166 var en = new CultureInfo (" en-US" );
8267 var sp = new CultureInfo (" es-ES" );
8368 var page = new Page (session );
8469 page .Localizations [en ].Title = " Welcome" ;
8570 page .Localizations [sp ].Title = " Bienvenido" ;
71+ ```
8672
87- 3 . Value of localizable properties reflects culture of the current Thread, e.g.:
73+ ** Example # 3 ** . Value of localizable properties reflects culture of the current Thread, e.g.:
8874
75+ ``` csharp
8976 Thread .CurrentThread .CurrentCulture = new CultureInfo (" en-US" );
9077 string title = page .Title ; // title is "Welcome"
9178
9279 Thread .CurrentThread .CurrentCulture = new CultureInfo (" es-ES" );
9380 string title = page .Title ; // title is "Bienvenido"
81+ ```
9482
95- 4 . Instead of altering CurrentThread, instance of LocalizationScope can be used, e.g.:
83+ ** Example # 4 ** . Instead of altering CurrentThread, instance of LocalizationScope can be used, e.g.:
9684
85+ ``` csharp
9786 using (new LocalizationScope (new CultureInfo (" en-US" ))) {
9887 string title = page .Title ; // title is "Welcome"
9988 }
10089
10190 using (new LocalizationScope (new CultureInfo (" es-ES" ))) {
10291 string title = page .Title ; // title is "Bienvenido"
10392 }
93+ ```
10494
105- 5 . LINQ queries that include localizable properties are transparently translated
95+ ** Example # 5 ** . LINQ queries that include localizable properties are transparently translated
10696
97+ ``` csharp
10798 Thread .CurrentThread .CurrentCulture = new CultureInfo (" en-US" );
10899 var query = from p in session .Query .All <Page >()
109100 where p .Title == " Welcome"
115106 where p .Title == " Bienvenido"
116107 select p ;
117108 Assert .AreEqual (1 , query .Count ());
118-
119-
120- References
121- ----------
122- http://doextensions.codeplex.com
109+ ```
0 commit comments