Added localization
This commit is contained in:
17
Program.cs
17
Program.cs
@@ -1,6 +1,9 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OneForMe.Data;
|
||||
using OneForMe.Services;
|
||||
using System.Globalization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -8,6 +11,16 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
// Add Localization
|
||||
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
|
||||
builder.Services.Configure<RequestLocalizationOptions>(options =>
|
||||
{
|
||||
var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("de") };
|
||||
options.DefaultRequestCulture = new RequestCulture("en");
|
||||
options.SupportedCultures = supportedCultures;
|
||||
options.SupportedUICultures = supportedCultures;
|
||||
});
|
||||
|
||||
// Add Swagger/OpenAPI
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
@@ -37,6 +50,9 @@ builder.Services.AddIdentity<IdentityUser, IdentityRole>(options =>
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
// Add LocalizationService
|
||||
builder.Services.AddScoped<LocalizationService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Create and migrate database on startup
|
||||
@@ -64,6 +80,7 @@ if (!app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseRequestLocalization();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
Reference in New Issue
Block a user