feat: 🎸 add first week of year option

This commit is contained in:
Jin 2025-03-29 13:34:47 +01:00
parent 0982a0e503
commit ec06503104
5 changed files with 72 additions and 2 deletions

View File

@ -35,6 +35,35 @@ const TPL = `
</div>
</div>
<div class="option-row">
<label id="first-week-of-year-label">${t("i18n.first-week-of-the-year")}</label>
<div role="group" aria-labelledby="first-week-of-year-label">
<label class="tn-radio">
<input name="first-week-of-year" type="radio" value="0" />
${t("i18n.first-week-contains-first-day")}
</label>
<label class="tn-radio">
<input name="first-week-of-year" type="radio" value="1" />
${t("i18n.first-week-contains-first-thursday")}
</label>
<label class="tn-radio">
<input name="first-week-of-year" type="radio" value="2" />
${t("i18n.first-week-has-minimum-days")}
</label>
</div>
</div>
<div class="option-row">
<label for="min-days-in-first-week">${t("i18n.min-days-in-first-week")}</label>
<select id="min-days-in-first-week" class="form-select">
${Array.from({length: 7}, (_, i) => i + 1)
.map(num => `<option value="${num}">${num}</option>`)
.join('')}
</select>
</div>
<div class="option-row centered">
<button class="btn btn-secondary btn-micro restart-app-button">${t("electron_integration.restart-app-button")}</button>
</div>
@ -64,6 +93,16 @@ const TPL = `
.locale-options-container .option-row.centered {
justify-content: center;
}
.locale-options-container .option-row [aria-labelledby="first-week-of-year-label"] {
display: flex;
flex-direction: column;
}
.locale-options-container .option-row [aria-labelledby="first-week-of-year-label"] .tn-radio {
margin-left: 0;
white-space: nowrap;
}
</style>
</div>
`;
@ -92,6 +131,17 @@ export default class LocalizationOptions extends OptionsWidget {
const firstDayOfWeek = String(this.$widget.find(`input[name="first-day-of-week"]:checked`).val());
this.updateOption("firstDayOfWeek", firstDayOfWeek);
});
this.$widget.find(`input[name="first-week-of-year"]`).on("change", () => {
const firstWeekOfYear = String(this.$widget.find(`input[name="first-week-of-year"]:checked`).val());
this.updateOption("firstWeekOfYear", firstWeekOfYear);
});
this.$widget.find("#min-days-in-first-week").on("change", () => {
const minDays = String(this.$widget.find("#min-days-in-first-week").val());
this.updateOption("minDaysInFirstWeek", minDays);
});
this.$widget.find(".restart-app-button").on("click", utils.restartDesktopApp);
}
@ -119,6 +169,11 @@ export default class LocalizationOptions extends OptionsWidget {
this.$formattingLocaleSelect.val(options.formattingLocale);
this.$widget.find(`input[name="first-day-of-week"][value="${options.firstDayOfWeek}"]`)
.prop("checked", "true");
.prop("checked", "true");
this.$widget.find(`input[name="first-week-of-year"][value="${options.firstWeekOfYear || '0'}"]`)
.prop("checked", "true");
this.$widget.find("#min-days-in-first-week").val(options.minDaysInFirstWeek || "4");
}
}

View File

@ -1232,7 +1232,13 @@
"language": "语言",
"first-day-of-the-week": "一周的第一天",
"sunday": "周日",
"monday": "周一"
"monday": "周一",
"first-week-of-the-year": "一年的第一周",
"first-week-contains-first-day": "第一周包含一年的第一天",
"first-week-contains-first-thursday": "第一周包含一年的第一个周四",
"first-week-has-minimum-days": "第一周有最小天数",
"min-days-in-first-week": "第一周的最小天数",
"formatting-locale": "日期和数字格式"
},
"backup": {
"automatic_backup": "自动备份",

View File

@ -1243,6 +1243,11 @@
"first-day-of-the-week": "First day of the week",
"sunday": "Sunday",
"monday": "Monday",
"first-week-of-the-year": "First week of the year",
"first-week-contains-first-day": "First week contains first day of the year",
"first-week-contains-first-thursday": "First week contains first Thursday of the year",
"first-week-has-minimum-days": "First week has minimum days",
"min-days-in-first-week": "Minimum days in first week",
"formatting-locale": "Date & number format"
},
"backup": {

View File

@ -143,6 +143,8 @@ const defaultOptions: DefaultOption[] = [
{ name: "locale", value: "en", isSynced: true },
{ name: "formattingLocale", value: "en", isSynced: true },
{ name: "firstDayOfWeek", value: "1", isSynced: true },
{ name: "firstWeekOfYear", value: "0", isSynced: true },
{ name: "minDaysInFirstWeek", value: "4", isSynced: true },
{ name: "languages", value: "[]", isSynced: true },
// Code block configuration

View File

@ -85,6 +85,8 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
eraseUnusedAttachmentsAfterSeconds: number;
eraseUnusedAttachmentsAfterTimeScale: number;
firstDayOfWeek: number;
firstWeekOfYear: number;
minDaysInFirstWeek: number;
languages: string;
// Appearance