Added localization

This commit is contained in:
2025-11-29 22:34:54 +01:00
parent 6819d1e38b
commit f930d9e408
9 changed files with 605 additions and 91 deletions

View File

@@ -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();