Add app-specific locale override

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD 2025-08-06 11:15:24 -06:00
parent 6fe4d5d84b
commit a7df12c88b
8 changed files with 41 additions and 3 deletions

View File

@ -6,6 +6,7 @@ using CarCareTracker.Helper;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using System.Security.Claims; using System.Security.Claims;
using CarCareTracker.Logic; using CarCareTracker.Logic;
using System.Globalization;
namespace CarCareTracker.Controllers namespace CarCareTracker.Controllers
{ {
@ -552,8 +553,13 @@ namespace CarCareTracker.Controllers
[Route("/setup")] [Route("/setup")]
public IActionResult Setup() public IActionResult Setup()
{ {
var installedLocales = CultureInfo.GetCultures(CultureTypes.AllCultures).Select(x=>x.Name).ToList();
installedLocales.RemoveAll(x => string.IsNullOrWhiteSpace(x));
installedLocales.Insert(0, "");
var viewModel = new ServerSettingsViewModel var viewModel = new ServerSettingsViewModel
{ {
LocaleOverride = _config.GetLocaleOverride(),
AvailableLocales = installedLocales,
PostgresConnection = _config.GetServerPostgresConnection(), PostgresConnection = _config.GetServerPostgresConnection(),
AllowedFileExtensions = _config.GetAllowedFileUploadExtensions(), AllowedFileExtensions = _config.GetAllowedFileUploadExtensions(),
CustomLogoURL = _config.GetLogoUrl(), CustomLogoURL = _config.GetLogoUrl(),

View File

@ -18,6 +18,7 @@ namespace CarCareTracker.Helper
bool AuthenticateRootUserOIDC(string email); bool AuthenticateRootUserOIDC(string email);
string GetWebHookUrl(); string GetWebHookUrl();
bool GetCustomWidgetsEnabled(); bool GetCustomWidgetsEnabled();
string GetLocaleOverride();
string GetMOTD(); string GetMOTD();
string GetLogoUrl(); string GetLogoUrl();
string GetSmallLogoUrl(); string GetSmallLogoUrl();
@ -73,6 +74,11 @@ namespace CarCareTracker.Helper
var domain = CheckString("LUBELOGGER_DOMAIN"); var domain = CheckString("LUBELOGGER_DOMAIN");
return domain; return domain;
} }
public string GetLocaleOverride()
{
var locale = CheckString("LUBELOGGER_LOCALE_OVERRIDE");
return locale;
}
public bool GetServerOpenRegistration() public bool GetServerOpenRegistration()
{ {
return CheckBool(CheckString("LUBELOGGER_OPEN_REGISTRATION")); return CheckBool(CheckString("LUBELOGGER_OPEN_REGISTRATION"));
@ -167,6 +173,10 @@ namespace CarCareTracker.Helper
{ {
serverConfig.PostgresConnection = null; serverConfig.PostgresConnection = null;
} }
if (string.IsNullOrWhiteSpace(serverConfig.LocaleOverride))
{
serverConfig.LocaleOverride = null;
}
if (serverConfig.AllowedFileExtensions == StaticHelper.DefaultAllowedFileExtensions || string.IsNullOrWhiteSpace(serverConfig.AllowedFileExtensions)) if (serverConfig.AllowedFileExtensions == StaticHelper.DefaultAllowedFileExtensions || string.IsNullOrWhiteSpace(serverConfig.AllowedFileExtensions))
{ {
serverConfig.AllowedFileExtensions = null; serverConfig.AllowedFileExtensions = null;

View File

@ -67,5 +67,9 @@ namespace CarCareTracker.Models
[JsonPropertyName("EnableRootUserOIDC")] [JsonPropertyName("EnableRootUserOIDC")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? EnableRootUserOIDC { get; set; } public bool? EnableRootUserOIDC { get; set; }
[JsonPropertyName("LUBELOGGER_LOCALE_OVERRIDE")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? LocaleOverride { get; set; } = string.Empty;
} }
} }

View File

@ -2,7 +2,7 @@ namespace CarCareTracker.Models
{ {
public class ServerSettingsViewModel public class ServerSettingsViewModel
{ {
public string LocaleInfo { get; set; } public string LocaleOverride { get; set; }
public string PostgresConnection { get; set; } public string PostgresConnection { get; set; }
public string AllowedFileExtensions { get; set; } public string AllowedFileExtensions { get; set; }
public string CustomLogoURL { get; set; } public string CustomLogoURL { get; set; }
@ -20,5 +20,6 @@ namespace CarCareTracker.Models
public string DefaultReminderEmail { get; set; } = string.Empty; public string DefaultReminderEmail { get; set; } = string.Empty;
public bool EnableRootUserOIDC { get; set; } public bool EnableRootUserOIDC { get; set; }
public bool EnableAuth { get; set; } public bool EnableAuth { get; set; }
public List<string> AvailableLocales { get; set; }
} }
} }

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using System.Globalization;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -15,6 +16,12 @@ var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile(StaticHelper.UserConfigPath, optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile(StaticHelper.UserConfigPath, optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile(StaticHelper.ServerConfigPath, optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile(StaticHelper.ServerConfigPath, optional: true, reloadOnChange: true);
if (!string.IsNullOrWhiteSpace(builder.Configuration["LUBELOGGER_LOCALE_OVERRIDE"]))
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(builder.Configuration["LUBELOGGER_LOCALE_OVERRIDE"]);
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(builder.Configuration["LUBELOGGER_LOCALE_OVERRIDE"]);
}
//Print Messages //Print Messages
StaticHelper.InitMessage(builder.Configuration); StaticHelper.InitMessage(builder.Configuration);
//Check Migration //Check Migration

View File

@ -53,9 +53,18 @@
</div> </div>
</div> </div>
</div> </div>
<small class="text-body-secondary">@translator.Translate(userLanguage, "Restart Required")</small> <small class="text-body-secondary">@translator.Translate(userLanguage, "Restart Required")</small>
</div> </div>
<div class="form-group">
<label for="inputLocale">@translator.Translate(userLanguage, "Locale Override")</label>
<select class="form-select" id="inputLocale">
@foreach(string installedLocale in Model.AvailableLocales)
{
<!option value="@installedLocale" @(Model.LocaleOverride == installedLocale ? "selected" : "")>@installedLocale</!option>
}
</select>
<small class="text-body-secondary">@translator.Translate(userLanguage, "Leave blank to use system locale. Restart Required")</small>
</div>
<div class="form-group"> <div class="form-group">
<label for="inputFileExt">@translator.Translate(userLanguage, "Allowed File Extensions")</label> <label for="inputFileExt">@translator.Translate(userLanguage, "Allowed File Extensions")</label>
<input type="text" id="inputFileExt" class="form-control" placeholder="@translator.Translate(userLanguage, "Not Configured")" value="@Model.AllowedFileExtensions"> <input type="text" id="inputFileExt" class="form-control" placeholder="@translator.Translate(userLanguage, "Not Configured")" value="@Model.AllowedFileExtensions">

File diff suppressed because one or more lines are too long

View File

@ -41,6 +41,7 @@ function previousSetupPage() {
} }
function saveSetup() { function saveSetup() {
let setupData = { let setupData = {
LocaleOverride: $("#inputLocale").val(),
PostgresConnection: $("#inputPostgres").val(), PostgresConnection: $("#inputPostgres").val(),
AllowedFileExtensions: $("#inputFileExt").val(), AllowedFileExtensions: $("#inputFileExt").val(),
CustomLogoURL: $("#inputLogoURL").val(), CustomLogoURL: $("#inputLogoURL").val(),