Introduction
After finishing a project, it was time to apply localization. I faced a problem and I would like to share the solution here.
Definitions
- Globalization is the process of designing apps that support different cultures. Globalization adds support for the input, display, and output of a defined set of language scripts that relate to specific geographic areas.
- Localization is the process of adapting a globalized app, which you have already processed for localizability, to a particular culture/locale.
The problem scope
I have added the localization in the middleware as below,
public class Startup {
public void ConfigureServices(IServiceCollection services) {
services.AddLocalization();
}
}
In my login page, I added the ability to choose a language from 2 options set (Arabic Or English) as shown in the image below,


In my login handling action. I called a function to specify the application culture as seen below,
public IActionResult LoginPost(EmployeeLogin EmployeeLoginModel) {
if (LoginObj.CheckLogin(_Context, EmployeeLoginModel)) {
SpecifyCulture();
}
}
private void SpecifyCulture() {
string lang = Request.Form["hdnLang"];
//hdnLang is a hidden field in the login form
//filled by a default value
//and this value gets changed when selecting an option from culture drop down
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(lang);
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
}
I have also created two resource files as seen below,






Join the conversation! Your thoughts help the community grow.