mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +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;
|
type DateTimeStyle = "full" | "long" | "medium" | "short" | "none" | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,7 +10,7 @@ export function formatDateTime(date: string | Date | number | null | undefined,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const locale = navigator.language;
|
const locale = options.get("formattingLocale") ?? options.get("locale") ?? navigator.language;
|
||||||
|
|
||||||
let parsedDate;
|
let parsedDate;
|
||||||
if (typeof date === "string" || typeof date === "number") {
|
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") {
|
if (timeStyle !== "none" && dateStyle !== "none") {
|
||||||
// Format the date and time
|
// 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);
|
return formatter.format(parsedDate);
|
||||||
} else if (timeStyle === "none" && dateStyle !== "none") {
|
} else if (timeStyle === "none" && dateStyle !== "none") {
|
||||||
// Format only the date
|
// Format only the date
|
||||||
|
@ -44,7 +44,7 @@ function LocalizationOptions() {
|
|||||||
<LocaleSelector locales={uiLocales} currentValue={locale} onChange={setLocale} />
|
<LocaleSelector locales={uiLocales} currentValue={locale} onChange={setLocale} />
|
||||||
</OptionsRow>
|
</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} />
|
<LocaleSelector locales={contentLocales} currentValue={formattingLocale} onChange={setFormattingLocale} />
|
||||||
</OptionsRow>}
|
</OptionsRow>}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user