mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(client/i18n): enable formatting locale on browser as well & use for date formatting
This commit is contained in:
parent
f4df7c1eec
commit
3c2642e822
@ -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
|
||||
|
@ -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>}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user