localization for ntfy and mail
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
export interface RuntimeSettings {
|
||||
paperlessBaseUrl: string | null;
|
||||
paperlessExternalUrl: string | null;
|
||||
appExternalUrl: string | null;
|
||||
appLocale: string;
|
||||
paperlessToken: string | null;
|
||||
schedulerIntervalMinutes: number;
|
||||
alertDaysBefore: number;
|
||||
@@ -65,6 +67,19 @@ function coerceString(value: unknown, fallback: string | null): string | null {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function normalizeLocale(value: unknown, fallback: string): string {
|
||||
if (typeof value === "string") {
|
||||
const lower = value.toLowerCase();
|
||||
if (lower.startsWith("de")) {
|
||||
return "de";
|
||||
}
|
||||
if (lower.startsWith("en")) {
|
||||
return "en";
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function getRuntimeSettings(): RuntimeSettings {
|
||||
const stored = listSettings();
|
||||
|
||||
@@ -78,6 +93,8 @@ export function getRuntimeSettings(): RuntimeSettings {
|
||||
return {
|
||||
paperlessBaseUrl: coerceString(stored.paperlessBaseUrl, config.paperlessBaseUrl ?? null),
|
||||
paperlessExternalUrl: coerceString(stored.paperlessExternalUrl, config.paperlessExternalUrl ?? null),
|
||||
appExternalUrl: coerceString(stored.appExternalUrl, config.appExternalUrl ?? null),
|
||||
appLocale: normalizeLocale(stored.appLocale, config.appLocale),
|
||||
paperlessToken: coerceString(stored.paperlessToken, config.paperlessToken ?? null),
|
||||
schedulerIntervalMinutes,
|
||||
alertDaysBefore,
|
||||
@@ -104,12 +121,16 @@ export function getRuntimeSettings(): RuntimeSettings {
|
||||
export function updateRuntimeSettings(update: Partial<RuntimeSettings>): RuntimeSettings {
|
||||
const keys = Object.keys(update) as SettingKey[];
|
||||
for (const key of keys) {
|
||||
const value = update[key as keyof RuntimeSettings];
|
||||
let value = update[key as keyof RuntimeSettings];
|
||||
if (value === undefined || value === null || value === "") {
|
||||
removeSetting(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key === "appLocale") {
|
||||
value = normalizeLocale(value, config.appLocale);
|
||||
}
|
||||
|
||||
if (numericKeys.has(key)) {
|
||||
const numericValue = coerceNumber(value, 0);
|
||||
setSetting(key, numericValue);
|
||||
|
||||
Reference in New Issue
Block a user