@@ -38,6 +38,8 @@ public class ui
38
38
[ Obsolete ( "Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext" ) ]
39
39
public static string Culture ( User u )
40
40
{
41
+ if ( ApplicationContext . Current == null ) return string . Empty ;
42
+
41
43
var found = UserExtensions . GetUserCulture ( u . Language , ApplicationContext . Current . Services . TextService ) ;
42
44
return found == null ? string . Empty : found . Name ;
43
45
}
@@ -46,6 +48,8 @@ public static string Culture(User u)
46
48
[ Obsolete ( "Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext" ) ]
47
49
internal static string Culture ( IUser u )
48
50
{
51
+ if ( ApplicationContext . Current == null ) return string . Empty ;
52
+
49
53
var found = u . GetUserCulture ( ApplicationContext . Current . Services . TextService ) ;
50
54
return found == null ? string . Empty : found . Name ;
51
55
}
@@ -94,11 +98,15 @@ private static string GetLanguage(string userLanguage)
94
98
/// <returns></returns>
95
99
public static string Text ( string Key , User u )
96
100
{
101
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
102
+
97
103
return ApplicationContext . Current . Services . TextService . Localize ( Key , GetCultureFromUserLanguage ( GetLanguage ( u ) ) ) ;
98
104
}
99
105
100
106
internal static string Text ( string key , IUser u )
101
107
{
108
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
109
+
102
110
return ApplicationContext . Current . Services . TextService . Localize ( key , GetCultureFromUserLanguage ( GetLanguage ( u ) ) ) ;
103
111
}
104
112
@@ -109,6 +117,8 @@ internal static string Text(string key, IUser u)
109
117
/// <returns></returns>
110
118
public static string Text ( string Key )
111
119
{
120
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
121
+
112
122
return ApplicationContext . Current . Services . TextService . Localize ( Key , GetCultureFromUserLanguage ( GetLanguage ( ) ) ) ;
113
123
}
114
124
@@ -121,13 +131,17 @@ public static string Text(string Key)
121
131
/// <returns></returns>
122
132
public static string Text ( string Area , string Key , User u )
123
133
{
134
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
135
+
124
136
return ApplicationContext . Current . Services . TextService . Localize (
125
137
string . Format ( "{0}/{1}" , Area , Key ) ,
126
138
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ) ;
127
139
}
128
140
129
141
public static string Text ( string area , string key , IUser u )
130
142
{
143
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
144
+
131
145
return ApplicationContext . Current . Services . TextService . Localize (
132
146
string . Format ( "{0}/{1}" , area , key ) ,
133
147
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ) ;
@@ -141,6 +155,8 @@ public static string Text(string area, string key, IUser u)
141
155
/// <returns></returns>
142
156
public static string Text ( string Area , string Key )
143
157
{
158
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
159
+
144
160
return ApplicationContext . Current . Services . TextService . Localize (
145
161
string . Format ( "{0}/{1}" , Area , Key ) ,
146
162
GetCultureFromUserLanguage ( GetLanguage ( ) ) ) ;
@@ -156,6 +172,8 @@ public static string Text(string Area, string Key)
156
172
/// <returns></returns>
157
173
public static string Text ( string Area , string Key , string [ ] Variables , User u )
158
174
{
175
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
176
+
159
177
return ApplicationContext . Current . Services . TextService . Localize (
160
178
string . Format ( "{0}/{1}" , Area , Key ) ,
161
179
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ,
@@ -164,6 +182,8 @@ public static string Text(string Area, string Key, string[] Variables, User u)
164
182
165
183
internal static string Text ( string area , string key , string [ ] variables )
166
184
{
185
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
186
+
167
187
return ApplicationContext . Current . Services . TextService . Localize (
168
188
string . Format ( "{0}/{1}" , area , key ) ,
169
189
GetCultureFromUserLanguage ( GetLanguage ( ) ) ,
@@ -172,6 +192,8 @@ internal static string Text(string area, string key, string[] variables)
172
192
173
193
internal static string Text ( string area , string key , string [ ] variables , IUser u )
174
194
{
195
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
196
+
175
197
return ApplicationContext . Current . Services . TextService . Localize (
176
198
string . Format ( "{0}/{1}" , area , key ) ,
177
199
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ,
@@ -188,6 +210,8 @@ internal static string Text(string area, string key, string[] variables, IUser u
188
210
/// <returns></returns>
189
211
public static string Text ( string Area , string Key , string Variable , User u )
190
212
{
213
+ if ( ApplicationContext . Current == null ) return "[" + Key + "]" ;
214
+
191
215
return ApplicationContext . Current . Services . TextService . Localize (
192
216
string . Format ( "{0}/{1}" , Area , Key ) ,
193
217
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ,
@@ -196,6 +220,8 @@ public static string Text(string Area, string Key, string Variable, User u)
196
220
197
221
internal static string Text ( string area , string key , string variable )
198
222
{
223
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
224
+
199
225
return ApplicationContext . Current . Services . TextService . Localize (
200
226
string . Format ( "{0}/{1}" , area , key ) ,
201
227
GetCultureFromUserLanguage ( GetLanguage ( ) ) ,
@@ -204,6 +230,8 @@ internal static string Text(string area, string key, string variable)
204
230
205
231
internal static string Text ( string area , string key , string variable , IUser u )
206
232
{
233
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
234
+
207
235
return ApplicationContext . Current . Services . TextService . Localize (
208
236
string . Format ( "{0}/{1}" , area , key ) ,
209
237
GetCultureFromUserLanguage ( GetLanguage ( u ) ) ,
@@ -228,6 +256,8 @@ public static string GetText(string key)
228
256
/// <returns></returns>
229
257
public static string GetText ( string area , string key )
230
258
{
259
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
260
+
231
261
return ApplicationContext . Current . Services . TextService . Localize (
232
262
string . Format ( "{0}/{1}" , area , key ) ,
233
263
GetCultureFromUserLanguage ( GetLanguage ( ) ) ) ;
@@ -242,6 +272,8 @@ public static string GetText(string area, string key)
242
272
/// <returns></returns>
243
273
public static string GetText ( string area , string key , string [ ] variables )
244
274
{
275
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
276
+
245
277
return ApplicationContext . Current . Services . TextService . Localize (
246
278
string . Format ( "{0}/{1}" , area , key ) ,
247
279
GetCultureFromUserLanguage ( GetLanguage ( ) ) ,
@@ -257,6 +289,8 @@ public static string GetText(string area, string key, string[] variables)
257
289
/// <returns></returns>
258
290
public static string GetText ( string area , string key , string variable )
259
291
{
292
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
293
+
260
294
return ApplicationContext . Current . Services . TextService . Localize (
261
295
string . Format ( "{0}/{1}" , area , key ) ,
262
296
GetCultureFromUserLanguage ( GetLanguage ( ) ) ,
@@ -274,6 +308,8 @@ public static string GetText(string area, string key, string variable)
274
308
/// <remarks>This is the underlying call for all Text/GetText method calls</remarks>
275
309
public static string GetText ( string area , string key , string [ ] variables , string language )
276
310
{
311
+ if ( ApplicationContext . Current == null ) return "[" + key + "]" ;
312
+
277
313
return ApplicationContext . Current . Services . TextService . Localize (
278
314
string . Format ( "{0}/{1}" , area , key ) ,
279
315
GetCultureFromUserLanguage ( GetLanguage ( ) ) ,
0 commit comments