I have asp.net core application which I want to localize and translate (v 1.1.0). I want the source code to support both english and norwegian deployments, and I found this could be a startup.cs configuration
RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
{
SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("nb-NO") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("nb-NO") },
DefaultRequestCulture = new RequestCulture("nb-NO")
};
app.UseRequestLocalization(localizationOptions);
However I want to have only one culture and one ui-culture for each deployment, so I hoped to find out a way to set culture and ui-culture in appsettings.json or enviroment variables. Is it possible?
To have ASP.NET set the UI culture and culture to the first language that is specified in the current browser settings, set UICulture and Culture to auto. Alternatively, you can set this value to auto:culture_info_name, where culture_info_name is a culture name. For a list of culture names, see CultureInfo.
Globalization is the process of designing and developing applications that function for multiple cultures. Localization is the process of customizing your application for a given culture and locale.
The appsettings. json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information.
Sure.
appsettings.json
:
{
"SiteLocale" : "en-US"
}
Startup.cs
:
var locale = Configuration["SiteLocale"];
RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
{
SupportedCultures = new List<CultureInfo> { new CultureInfo(locale) },
SupportedUICultures = new List<CultureInfo> { new CultureInfo(locale) },
DefaultRequestCulture = new RequestCulture(locale)
};
app.UseRequestLocalization(localizationOptions);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With