I have a web-api project that has several controllers, I implemented localization (English and Korean) for it but want one or two controllers return messages in English even when the language is Korean (don't want use simple English message and want to read from English resource)
Is it possible?
I setup localization like below:
services.Configure<RequestLocalizationOptions>(options =>
{
var cultures = new List<CultureInfo> {
new CultureInfo("en"),
new CultureInfo("kr")
};
options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en");
options.SupportedCultures = cultures;
options.SupportedUICultures = cultures;
});
services.AddMvc().AddDataAnnotationsLocalization(options =>
{
options.DataAnnotationLocalizerProvider = (type, factory) =>factory.Create(typeof(SharedTranslate));
});
services.AddLocalization(o =>
{
o.ResourcesPath = "Resources";
});
and in constructor :
public AuthAdminController(IStringLocalizer<SharedTranslate> localizer,...
I use below code in constructor of controller but didn't work
//First
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
//Second
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en");