Add per account locale setting

Add a per user account setting for the locale so that the server can
correctly render pages with localized time formatting.
This commit is contained in:
Hornwitser 2025-06-13 21:50:22 +02:00
parent fad1bb2482
commit fb7a60db28
5 changed files with 28 additions and 0 deletions

View file

@ -24,6 +24,15 @@ export default defineEventHandler(async (event) => {
});
}
}
if (patch.locale?.length) {
const locale = DateTime.local({ locale: patch.locale }).resolvedLocaleOptions().locale;
if (locale !== patch.locale) {
throw createError({
status: 400,
message: `Invalid locale: the locale "${patch.locale}" is not supported (was treated as "${locale}")`
});
}
}
const accounts = await readAccounts();
const sessionAccount = accounts.find(account => account.id === session.accountId);
@ -51,6 +60,12 @@ export default defineEventHandler(async (event) => {
else
delete sessionAccount.timezone;
}
if (patch.locale !== undefined) {
if (patch.locale)
sessionAccount.locale = patch.locale;
else
delete sessionAccount.locale;
}
await writeAccounts(accounts);
// Update Schedule counts.