Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

CultureInfo.CurrentCulture.Name not being set correctly in IE 11/Edge Windows 10

$
0
0

Hello All,

We have implemented Localization in MVC core application.Created resource files for each language.For Chinese, we have resource with zh-CN extension.

I see different behaviour of application when request is being made from google chrome and IE 11/Edge for Chinese language.

  1. Google Chrome - When request is being made from Chrome, in request header, i see accept-language as "zh-CN,zh;" and noticed that

CultureInfo.CurrentCulture.Name is correctly being set to zh-CN, hence application works perfectly.

  1. IE 11 - When request is being made from IE, in request header, i see accept-language as "zh-Hans-CN,zh-Hans;" and noticed that

CultureInfo.CurrentCulture.Name is set to en-Us(which is incorrect) and hence application fails to load in chinese language.

Here is the code snippet:

Config.json

"Localization": {
"DefaultLanguage": "en-US",
"SupportedLanguages": [
"en-US",
"fr-FR",
"de-DE",
"sv-SE",
"zh-CN",
"he-IL",
"he"
]
}

Startup.cs:

 applicationBuilder.UseRequestLocalization(this.AppSettings.Localization);

public static void UseRequestLocalization(this IApplicationBuilder applicationBuilder, LocalizationConfig localizationConfig)
{
var options = new RequestLocalizationOptions
{
SupportedCultures = localizationConfig.SupportedLanguages.Select(row => new CultureInfo(row)).ToList(),
SupportedUICultures = localizationConfig.SupportedLanguages.Select(row => new CultureInfo(row)).ToList(),
DefaultRequestCulture = new RequestCulture(localizationConfig.DefaultLanguage)
};

applicationBuilder.UseRequestLocalization(options);
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>