diff --git a/packages/frontend/i18n/src/__tests__/week-days.spec.ts b/packages/frontend/i18n/src/__tests__/week-days.spec.ts new file mode 100644 index 0000000000..daf2d222b1 --- /dev/null +++ b/packages/frontend/i18n/src/__tests__/week-days.spec.ts @@ -0,0 +1,48 @@ +import { describe, expect, test } from 'vitest'; + +import { type Language, SUPPORTED_LANGUAGES } from '../resources'; + +// The date picker splits this string and renders it as a Sunday-first header +const weekDaysKey = 'com.affine.calendar-date-picker.week-days'; + +async function loadWeekDays() { + const entries = await Promise.all( + Object.entries(SUPPORTED_LANGUAGES).map(async ([locale, { resource }]) => { + const loaded = + typeof resource === 'function' ? (await resource()).default : resource; + return { + locale: locale as Language, + labels: loaded[weekDaysKey]?.split(/[,،]/).map(label => label.trim()), + }; + }) + ); + return entries.filter( + (entry): entry is { locale: Language; labels: string[] } => !!entry.labels + ); +} + +const locales = await loadWeekDays(); + +describe('calendar week days', () => { + test.each(locales)('$locale has seven week days', ({ labels }) => { + expect(labels).toHaveLength(7); + }); + + // Single-character labels can be compared with the platform's narrow + // weekday names, which catches labels in the wrong order. + test.each( + locales.filter(({ labels }) => + labels.every(label => [...label].length === 1) + ) + )('$locale starts on Sunday', ({ locale, labels }) => { + const format = new Intl.DateTimeFormat(locale, { + weekday: 'narrow', + timeZone: 'UTC', + }); + // 2023-01-01 is a Sunday + const expected = Array.from({ length: 7 }, (_, day) => + format.format(new Date(Date.UTC(2023, 0, 1 + day))) + ); + expect(labels).toEqual(expected); + }); +}); diff --git a/packages/frontend/i18n/src/resources/fa.json b/packages/frontend/i18n/src/resources/fa.json index 08c4a0a078..af85765c7d 100644 --- a/packages/frontend/i18n/src/resources/fa.json +++ b/packages/frontend/i18n/src/resources/fa.json @@ -314,7 +314,7 @@ "com.affine.brand.affineCloud": "AFFiNE Cloud", "com.affine.calendar-date-picker.month-names": "ژانویه,فوریه,مارس,آوریل,مه,ژوئن,ژوئیه,اوت,سپتامبر,اکتبر,نوامبر,دسامبر", "com.affine.calendar-date-picker.today": "امروز", - "com.affine.calendar-date-picker.week-days": "ش,ی,د,س,چ,ج,ش", + "com.affine.calendar-date-picker.week-days": "ی,د,س,چ,پ,ج,ش", "com.affine.cloud-scroll-tip.caption": "میزبان توسط AFFiNE.Pro، ذخیره، همگام‌سازی و پشتیبان‌گیری از تمام داده‌های شما.", "com.affine.cloud-scroll-tip.title": "AFFiNE Cloud", "com.affine.cmdk.affine.category.affine.collections": "مجموعه‌ها",