Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(client/i18n): enable formatting locale on browser as well & use for date formatting
Elian Doran3c2642e822ac
diff --git a/apps/client/src/utils/formatters.ts b/apps/client/src/utils/formatters.tsindex d3209be7b3..664580c656 100644--- a/apps/client/src/utils/formatters.ts+++ b/apps/client/src/utils/formatters.ts@@ -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 datediff --git a/apps/client/src/widgets/type_widgets/options/i18n.tsx b/apps/client/src/widgets/type_widgets/options/i18n.tsxindex d69e2a3956..9ebca626b7 100644--- a/apps/client/src/widgets/type_widgets/options/i18n.tsx+++ b/apps/client/src/widgets/type_widgets/options/i18n.tsx@@ -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>}