File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,13 @@ public bool SetCurrentLanguage(string language)
71
71
{
72
72
try
73
73
{
74
+ #if NET6_0
74
75
CultureInfo . GetCultureInfo ( language , true ) ;
76
+ #else
77
+ if ( ! CultureExists ( language ) )
78
+ return false ;
79
+ #endif
80
+
75
81
}
76
82
catch
77
83
{
@@ -94,6 +100,17 @@ private void SetInvariantCulture()
94
100
Language = Thread . CurrentThread . CurrentCulture . TwoLetterISOLanguageName ;
95
101
}
96
102
103
+ private static bool CultureExists ( string name )
104
+ {
105
+ var availableCultures = CultureInfo . GetCultures ( CultureTypes . AllCultures ) ;
106
+
107
+ foreach ( CultureInfo culture in availableCultures )
108
+ if ( culture . Name . Equals ( name ) )
109
+ return true ;
110
+
111
+ return false ;
112
+ }
113
+
97
114
private bool TrySetLanguageFromCookie ( HttpContext context )
98
115
{
99
116
var cookieLanguage = context . Request . Cookies [ CookieLanguageFieldName ] ;
You can’t perform that action at this time.
0 commit comments