feat(i18n): add an option to automatically match formatting locale to set locale

This commit is contained in:
Elian Doran 2025-10-09 18:54:55 +03:00
parent 6d9bdd5c6f
commit ea4fe3f290
No known key found for this signature in database
5 changed files with 10 additions and 6 deletions

View File

@ -1424,7 +1424,8 @@
"min-days-in-first-week": "Minimum days in first week", "min-days-in-first-week": "Minimum days in first week",
"first-week-info": "First week contains first Thursday of the year is based on <a href=\"https://en.wikipedia.org/wiki/ISO_week_date#First_week\">ISO 8601</a> standard.", "first-week-info": "First week contains first Thursday of the year is based on <a href=\"https://en.wikipedia.org/wiki/ISO_week_date#First_week\">ISO 8601</a> standard.",
"first-week-warning": "Changing first week options may cause duplicate with existing Week Notes and the existing Week Notes will not be updated accordingly.", "first-week-warning": "Changing first week options may cause duplicate with existing Week Notes and the existing Week Notes will not be updated accordingly.",
"formatting-locale": "Date & number format" "formatting-locale": "Date & number format",
"formatting-locale-auto": "Based on the application's language"
}, },
"backup": { "backup": {
"automatic_backup": "Automatic backup", "automatic_backup": "Automatic backup",

View File

@ -10,7 +10,7 @@ export function formatDateTime(date: string | Date | number | null | undefined,
return ""; return "";
} }
const locale = options.get("formattingLocale") ?? options.get("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") {

View File

@ -23,7 +23,7 @@ export default function InternationalizationOptions() {
} }
function LocalizationOptions() { function LocalizationOptions() {
const { uiLocales, formattingLocales: contentLocales } = useMemo(() => { const { uiLocales, formattingLocales: contentLocales } = useMemo<{ uiLocales: Locale[], formattingLocales: Locale[] }>(() => {
const allLocales = getAvailableLocales(); const allLocales = getAvailableLocales();
return { return {
uiLocales: allLocales.filter(locale => { uiLocales: allLocales.filter(locale => {
@ -31,7 +31,10 @@ function LocalizationOptions() {
if (locale.devOnly && !glob.isDev) return false; if (locale.devOnly && !glob.isDev) return false;
return true; return true;
}), }),
formattingLocales: allLocales.filter(locale => locale.electronLocale), formattingLocales: [
{ id: "", name: t("i18n.formatting-locale-auto") },
...allLocales.filter(locale => locale.electronLocale)
]
} }
}, []); }, []);

View File

@ -30,7 +30,7 @@ async function main() {
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271 // needed for excalidraw export https://github.com/zadam/trilium/issues/4271
app.commandLine.appendSwitch("enable-experimental-web-platform-features"); app.commandLine.appendSwitch("enable-experimental-web-platform-features");
app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en"); app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") || options.getOptionOrNull("locale") || "en");
// Disable smooth scroll if the option is set // Disable smooth scroll if the option is set
const smoothScrollEnabled = options.getOptionOrNull("smoothScrollEnabled"); const smoothScrollEnabled = options.getOptionOrNull("smoothScrollEnabled");

View File

@ -159,7 +159,7 @@ const defaultOptions: DefaultOption[] = [
// Internationalization // Internationalization
{ name: "locale", value: "en", isSynced: true }, { name: "locale", value: "en", isSynced: true },
{ name: "formattingLocale", value: "en", isSynced: true }, { name: "formattingLocale", value: "", isSynced: true }, // no value means auto-detect
{ name: "firstDayOfWeek", value: "1", isSynced: true }, { name: "firstDayOfWeek", value: "1", isSynced: true },
{ name: "firstWeekOfYear", value: "0", isSynced: true }, { name: "firstWeekOfYear", value: "0", isSynced: true },
{ name: "minDaysInFirstWeek", value: "4", isSynced: true }, { name: "minDaysInFirstWeek", value: "4", isSynced: true },