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.
- 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.
- 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);
}