Added DefaultLanguage Customization

This commit is contained in:
Mia Rose Winter 2024-02-20 12:23:42 +01:00
parent a3033e8646
commit d6a70d0a03
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 9 additions and 6 deletions

File diff suppressed because one or more lines are too long

View file

@ -5,6 +5,7 @@ public class Customization {
public string AppDescription { get; set; } = "";
public string AppUrl { get; set; } = "http://localhost";
public string DefaultTheme { get; set; } = "";
public string DefaultLanguage { get; set; } = "";
public string LogoLink { get; set; } = "";
public string Footer { get; set; } = "";
}

View file

@ -173,13 +173,15 @@
#endregion
var customization = builder.Configuration.GetSection(nameof(Customization)).Get<Customization>();
string[] cultures = ["en-US", "en-GB", "de-DE"];
string defaultLanguage = string.IsNullOrWhiteSpace(customization?.DefaultLanguage) ? cultures[0] : customization.DefaultLanguage;
builder.Services.Configure<RequestLocalizationOptions>(options => {
options.ApplyCurrentCultureToResponseHeaders = true;
options.FallBackToParentCultures = true;
options.FallBackToParentUICultures = true;
options.SetDefaultCulture(cultures[0])
options.SetDefaultCulture(defaultLanguage)
.AddSupportedCultures(cultures)
.AddSupportedUICultures(cultures);
});
@ -221,15 +223,15 @@
{
using var scope = app.Services.CreateScope();
using var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await using var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
context.Database.Migrate();
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
if (userManager.GetUsersInRoleAsync("Admin").Result.Any() is false) {
IDistributedCache cache = app.Services.GetRequiredService<IDistributedCache>();
var cache = app.Services.GetRequiredService<IDistributedCache>();
// Check first wheter the password exists already
string admin = await cache.GetStringAsync("admin_promote_key");
string? admin = await cache.GetStringAsync("admin_promote_key");
// If it does not exist, create a new one and save it to redis
if (string.IsNullOrWhiteSpace(admin)){