feat(client/i18n): enable formatting locale on browser as well & use for date formatting

This commit is contained in:
Elian Doran 2025-10-09 18:44:35 +03:00
parent f4df7c1eec
commit 3c2642e822
No known key found for this signature in database
2 changed files with 5 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import options from "../services/options";
type DateTimeStyle = "full" | "long" | "medium" | "short" | "none" | undefined;
/**
@ -8,7 +10,7 @@ export function formatDateTime(date: string | Date | number | null | undefined,
return "";
}
const locale = navigator.language;
const locale = options.get("formattingLocale") ?? options.get("locale") ?? navigator.language;
let parsedDate;
if (typeof date === "string" || typeof date === "number") {
@ -24,7 +26,7 @@ export function formatDateTime(date: string | Date | number | null | undefined,
if (timeStyle !== "none" && dateStyle !== "none") {
// Format the date and time
const formatter = new Intl.DateTimeFormat(navigator.language, { dateStyle, timeStyle });
const formatter = new Intl.DateTimeFormat(locale, { dateStyle, timeStyle });
return formatter.format(parsedDate);
} else if (timeStyle === "none" && dateStyle !== "none") {
// Format only the date

View File

@ -44,7 +44,7 @@ function LocalizationOptions() {
<LocaleSelector locales={uiLocales} currentValue={locale} onChange={setLocale} />
</OptionsRow>
{isElectron() && <OptionsRow name="formatting-locale" label={t("i18n.formatting-locale")}>
{<OptionsRow name="formatting-locale" label={t("i18n.formatting-locale")}>
<LocaleSelector locales={contentLocales} currentValue={formattingLocale} onChange={setFormattingLocale} />
</OptionsRow>}