calendar display type supports Gregorian with Persian, date display type supports Persian calendar

This commit is contained in:
MaysWind
2025-09-06 23:02:09 +08:00
parent 757f9e5b02
commit a469d66358
24 changed files with 209 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
{
"monthNames": [
"فروردین",
"اردیبهشت",
"خرداد",
"تیر",
"مرداد",
"شهریور",
"مهر",
"آبان",
"آذر",
"دی",
"بهمن",
"اسفند"
],
"monthShortNames": [
"فرو",
"ارد",
"خرد",
"تیر",
"مرد",
"شهر",
"مهر",
"آبا",
"آذر",
"دی",
"بهم",
"اسف"
]
}
+12
View File
@@ -0,0 +1,12 @@
import fa from './fa.json';
type PersianCalendarLocaleDataKey = 'monthNames' | 'monthShortNames';
type PersianCalendarLocaleData = {
[K in PersianCalendarLocaleDataKey]: string[];
};
export const DEFAULT_CONTENT: PersianCalendarLocaleData = fa;
export const ALL_LANGUAGES: Record<string, PersianCalendarLocaleData> = {
'fa': fa
}
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+54 -1
View File
@@ -16,18 +16,25 @@ import {
DEFAULT_CONTENT as CHINESE_CALENDAR_DEFAULT_CONTENT
} from '@/locales/calendar/chinese/index.ts';
import {
ALL_LANGUAGES as PERSIAN_CALENDAR_ALL_LANGUAGES,
DEFAULT_CONTENT as PERSIAN_CALENDAR_DEFAULT_CONTENT
} from '@/locales/calendar/persian/index.ts';
import {
TextDirection
} from '@/core/text.ts';
import {
type ChineseCalendarLocaleData,
type PersianCalendarLocaleData,
CalendarType,
CalendarDisplayType,
DateDisplayType
} from '@/core/calendar.ts';
import {
type DateTime,
type DateTimeFormatOptions,
type DateTimeLocaleData,
type TextualYearMonth,
@@ -174,7 +181,9 @@ import {
getBrowserTimezoneOffset,
getBrowserTimezoneOffsetMinutes,
getCurrentUnixTime,
getYearMonthDayDateTime,
parseDateTimeFromUnixTime,
getGregorianCalendarYearMonthDays,
getDateTimeFormatType,
getFiscalYearTimeRangeFromUnixTime,
getFiscalYearTimeRangeFromYear,
@@ -481,6 +490,16 @@ export function useI18n() {
return chineseCalendarLocaleData;
}
function getPersianCalendarLocaleData(): PersianCalendarLocaleData {
const localeData = PERSIAN_CALENDAR_ALL_LANGUAGES[locale.value] ?? PERSIAN_CALENDAR_DEFAULT_CONTENT;
const persianCalendarLocaleData: PersianCalendarLocaleData = {
monthNames: localeData['monthNames'],
monthShortNames: localeData['monthShortNames']
};
return persianCalendarLocaleData;
}
function getAllCurrencyDisplayTypes(numeralSystem: NumeralSystem, decimalSeparator: string): TypeAndDisplayName[] {
const defaultCurrencyDisplayTypeName = t('default.currencyDisplayType');
let defaultCurrencyDisplayType = CurrencyDisplayType.parse(defaultCurrencyDisplayTypeName);
@@ -713,7 +732,8 @@ export function useI18n() {
numeralSystem: numeralSystem,
calendarType: calendarType,
localeData: getDateTimeLocaleData(),
chineseCalendarLocaleData: getChineseCalendarLocaleData()
chineseCalendarLocaleData: getChineseCalendarLocaleData(),
persianCalendarLocaleData: getPersianCalendarLocaleData()
};
}
@@ -773,6 +793,24 @@ export function useI18n() {
return currencyDisplayType;
}
function getCalendarAlternateDisplayDate(dateTime: DateTime, dateTimeFormatOptions: DateTimeFormatOptions): CalendarAlternateDate {
const numeralSystem = getCurrentNumeralSystemType();
let displayDate = numeralSystem.replaceWesternArabicDigitsToLocalizedDigits(dateTime.getLocalizedCalendarDay(dateTimeFormatOptions));
if (dateTime.isLocalizedCalendarFirstDayOfMonth(dateTimeFormatOptions)) {
displayDate = dateTime.getLocalizedCalendarMonthDisplayShortName(dateTimeFormatOptions);
}
const alternateDate: CalendarAlternateDate = {
year: dateTime.getGregorianCalendarYear(),
month: dateTime.getGregorianCalendarMonth(),
day: dateTime.getGregorianCalendarDay(),
displayDate: displayDate
};
return alternateDate;
}
// public functions
function translateIf(text: string | undefined, isTranslate?: boolean): string {
if (!isDefined(text)) {
@@ -1922,6 +1960,17 @@ export function useI18n() {
ret.push(alternateDate);
}
return ret;
} else if (calendarDisplayType === CalendarType.Persian) {
const dateTimeFormatOptions = getDateTimeFormatOptions();
const monthDays: number = getGregorianCalendarYearMonthDays(yearMonth);
const ret: CalendarAlternateDate[] = [];
for (let i = 1; i <= monthDays; i++) {
const dateTime = getYearMonthDayDateTime(yearMonth.year, yearMonth.month1base, i);
ret.push(getCalendarAlternateDisplayDate(dateTime, dateTimeFormatOptions));
}
return ret;
}
@@ -1944,6 +1993,10 @@ export function useI18n() {
}
return getChineseCalendarAlternateDisplayDate(chineseDate);
} else if (calendarDisplayType === CalendarType.Persian) {
const dateTimeFormatOptions = getDateTimeFormatOptions();
const dateTime = getYearMonthDayDateTime(yearMonthDay.year, yearMonthDay.month, yearMonthDay.day);
return getCalendarAlternateDisplayDate(dateTime, dateTimeFormatOptions);
}
return undefined;
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "Gregorian",
"Buddhist": "Buddhist",
"Gregorian with Chinese": "Gregorian with Chinese"
"Persian": "Persian",
"Gregorian with Chinese": "Gregorian with Chinese",
"Gregorian with Persian": "Gregorian with Persian"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "公历",
"Buddhist": "佛教日历",
"Gregorian with Chinese": "公历+农历"
"Persian": "伊朗历",
"Gregorian with Chinese": "公历+农历",
"Gregorian with Persian": "公历+伊朗历"
},
"datetime": {
"AM": {
+3 -1
View File
@@ -139,7 +139,9 @@
"calendar": {
"Gregorian": "公曆",
"Buddhist": "佛曆",
"Gregorian with Chinese": "公曆+農曆"
"Persian": "伊朗曆",
"Gregorian with Chinese": "公曆+農曆",
"Gregorian with Persian": "公曆+伊朗曆"
},
"datetime": {
"AM": {