1
- =========================
2
1
Xtensive.Orm.Localization
3
2
=========================
4
3
@@ -9,35 +8,14 @@ This implies that localizable resources are a part of domain model so they are s
9
8
10
9
Prerequisites
11
10
-------------
12
- DataObjects.Net Core 0.1 or later (http://dataobjects.net)
11
+ DataObjects.Net 6.0.x or later (http://dataobjects.net )
13
12
14
13
Implementation
15
14
--------------
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.:
40
15
16
+ Implement ILocalizable<TLocalization > on your localizable entities, e.g.:
17
+
18
+ ``` csharp
41
19
[HierarchyRoot ]
42
20
public class Page : Entity , ILocalizable <PageLocalization >
43
21
{
@@ -56,9 +34,11 @@ Implementation
56
34
57
35
public Page (Session session ) : base (session ) {}
58
36
}
37
+ ```
59
38
60
- 4. Define corresponding localizations, e.g.:
39
+ Define corresponding localizations, e.g.:
61
40
41
+ ``` csharp
62
42
[HierarchyRoot ]
63
43
public class PageLocalization : Localization <Page >
64
44
{
@@ -68,42 +48,53 @@ Implementation
68
48
public PageLocalization (Session session , CultureInfo culture , Page target )
69
49
: base (session , culture , target ) {}
70
50
}
51
+ ```
52
+
53
+ Examples of usage
54
+ -----------------
71
55
72
- Demo
73
- ----
74
- 1. Access localizable properties as regular ones, e.g.:
56
+ ** Example #1 ** . Access localizable properties as regular ones, e.g.:
75
57
58
+ ``` csharp
76
59
page .Title = " Welcome" ;
77
60
string title = page .Title ;
61
+ ```
78
62
79
- 2 . Mass editing of localizable properties:
63
+ ** Example # 2 ** . Mass editing of localizable properties:
80
64
65
+ ``` csharp
81
66
var en = new CultureInfo (" en-US" );
82
67
var sp = new CultureInfo (" es-ES" );
83
68
var page = new Page (session );
84
69
page .Localizations [en ].Title = " Welcome" ;
85
70
page .Localizations [sp ].Title = " Bienvenido" ;
71
+ ```
86
72
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.:
88
74
75
+ ``` csharp
89
76
Thread .CurrentThread .CurrentCulture = new CultureInfo (" en-US" );
90
77
string title = page .Title ; // title is "Welcome"
91
78
92
79
Thread .CurrentThread .CurrentCulture = new CultureInfo (" es-ES" );
93
80
string title = page .Title ; // title is "Bienvenido"
81
+ ```
94
82
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.:
96
84
85
+ ``` csharp
97
86
using (new LocalizationScope (new CultureInfo (" en-US" ))) {
98
87
string title = page .Title ; // title is "Welcome"
99
88
}
100
89
101
90
using (new LocalizationScope (new CultureInfo (" es-ES" ))) {
102
91
string title = page .Title ; // title is "Bienvenido"
103
92
}
93
+ ```
104
94
105
- 5 . LINQ queries that include localizable properties are transparently translated
95
+ ** Example # 5 ** . LINQ queries that include localizable properties are transparently translated
106
96
97
+ ``` csharp
107
98
Thread .CurrentThread .CurrentCulture = new CultureInfo (" en-US" );
108
99
var query = from p in session .Query .All <Page >()
109
100
where p .Title == " Welcome"
115
106
where p .Title == " Bienvenido"
116
107
select p ;
117
108
Assert .AreEqual (1 , query .Count ());
118
-
119
-
120
- References
121
- ----------
122
- http://doextensions.codeplex.com
109
+ ```
0 commit comments