-
-
Notifications
You must be signed in to change notification settings - Fork 8
Setup for MVC
Ziya Mollamahmut edited this page Mar 19, 2020
·
5 revisions
Configure ExpressLocalization in startup.cs
:
using System.Globalization;
using LazZiya.ExpressLocalization;
using Microsoft.AspNetCore.Localization;
//setup express localization under ConfigureServices method:
public void ConfigureServices(IServiceCollection services)
{
// Other configuration settings....
var cultures = new CultureInfo[]
{
new CultureInfo("en"),
new CultureInfo("tr"),
new CultureInfo("ar")
};
services.AddControllersWithViews()
.AddExpressLocalization<LocalizationResource>(
ops =>
{
ops.ResourcesPath = "LocalizationResources";
ops.RequestLocalizationOptions = o =>
{
o.SupportedCultures = cultures;
o.SupportedUICultures = cultures;
o.DefaultRequestCulture = new RequestCulture("en");
};
});
}
Use RequestLocalization
middleware :
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Other codes...
// Use localization middleware
app.UseRequestLocalization();
// Add {culture} to the route
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{culture=en}/{controller=Home}/{action=Index}/{id?}");
});
}
4.0, 3.2, 3.1, 3.0, 2.0, 1.1, 1.0