mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 16:24:25 +08:00
calendar display type supports Gregorian with Chinese
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import zhHans from './zh_Hans.json';
|
||||
import zhHant from './zh_Hant.json';
|
||||
|
||||
type ChineseCalendarLocaleDataKey = 'numerals' | 'monthNames' | 'dayNames' | 'leapMonthPrefix' | 'solarTermNames';
|
||||
type ChineseCalendarLocaleData = {
|
||||
[K in ChineseCalendarLocaleDataKey]: K extends 'leapMonthPrefix' ? string : string[];
|
||||
};
|
||||
|
||||
export const DEFAULT_CONTENT: ChineseCalendarLocaleData = zhHans;
|
||||
|
||||
export const ALL_LANGUAGES: Record<string, ChineseCalendarLocaleData> = {
|
||||
'zh-Hans': zhHans,
|
||||
'zh-Hant': zhHant
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"numerals": [
|
||||
"〇",
|
||||
"一",
|
||||
"二",
|
||||
"三",
|
||||
"四",
|
||||
"五",
|
||||
"六",
|
||||
"七",
|
||||
"八",
|
||||
"九",
|
||||
"十"
|
||||
],
|
||||
"monthNames": [
|
||||
"正月",
|
||||
"二月",
|
||||
"三月",
|
||||
"四月",
|
||||
"五月",
|
||||
"六月",
|
||||
"七月",
|
||||
"八月",
|
||||
"九月",
|
||||
"十月",
|
||||
"冬月",
|
||||
"腊月"
|
||||
],
|
||||
"dayNames": [
|
||||
"初一",
|
||||
"初二",
|
||||
"初三",
|
||||
"初四",
|
||||
"初五",
|
||||
"初六",
|
||||
"初七",
|
||||
"初八",
|
||||
"初九",
|
||||
"初十",
|
||||
"十一",
|
||||
"十二",
|
||||
"十三",
|
||||
"十四",
|
||||
"十五",
|
||||
"十六",
|
||||
"十七",
|
||||
"十八",
|
||||
"十九",
|
||||
"二十",
|
||||
"廿一",
|
||||
"廿二",
|
||||
"廿三",
|
||||
"廿四",
|
||||
"廿五",
|
||||
"廿六",
|
||||
"廿七",
|
||||
"廿八",
|
||||
"廿九",
|
||||
"三十"
|
||||
],
|
||||
"leapMonthPrefix": "闰",
|
||||
"solarTermNames": [
|
||||
"小寒",
|
||||
"大寒",
|
||||
"立春",
|
||||
"雨水",
|
||||
"惊蛰",
|
||||
"春分",
|
||||
"清明",
|
||||
"谷雨",
|
||||
"立夏",
|
||||
"小满",
|
||||
"芒种",
|
||||
"夏至",
|
||||
"小暑",
|
||||
"大暑",
|
||||
"立秋",
|
||||
"处暑",
|
||||
"白露",
|
||||
"秋分",
|
||||
"寒露",
|
||||
"霜降",
|
||||
"立冬",
|
||||
"小雪",
|
||||
"大雪",
|
||||
"冬至"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"numerals": [
|
||||
"〇",
|
||||
"一",
|
||||
"二",
|
||||
"三",
|
||||
"四",
|
||||
"五",
|
||||
"六",
|
||||
"七",
|
||||
"八",
|
||||
"九",
|
||||
"十"
|
||||
],
|
||||
"monthNames": [
|
||||
"正月",
|
||||
"二月",
|
||||
"三月",
|
||||
"四月",
|
||||
"五月",
|
||||
"六月",
|
||||
"七月",
|
||||
"八月",
|
||||
"九月",
|
||||
"十月",
|
||||
"冬月",
|
||||
"腊月"
|
||||
],
|
||||
"dayNames": [
|
||||
"初一",
|
||||
"初二",
|
||||
"初三",
|
||||
"初四",
|
||||
"初五",
|
||||
"初六",
|
||||
"初七",
|
||||
"初八",
|
||||
"初九",
|
||||
"初十",
|
||||
"十一",
|
||||
"十二",
|
||||
"十三",
|
||||
"十四",
|
||||
"十五",
|
||||
"十六",
|
||||
"十七",
|
||||
"十八",
|
||||
"十九",
|
||||
"二十",
|
||||
"廿一",
|
||||
"廿二",
|
||||
"廿三",
|
||||
"廿四",
|
||||
"廿五",
|
||||
"廿六",
|
||||
"廿七",
|
||||
"廿八",
|
||||
"廿九",
|
||||
"三十"
|
||||
],
|
||||
"leapMonthPrefix": "閏",
|
||||
"solarTermNames": [
|
||||
"小寒",
|
||||
"大寒",
|
||||
"立春",
|
||||
"雨水",
|
||||
"驚蟄",
|
||||
"春分",
|
||||
"清明",
|
||||
"穀雨",
|
||||
"立夏",
|
||||
"小滿",
|
||||
"芒種",
|
||||
"夏至",
|
||||
"小暑",
|
||||
"大暑",
|
||||
"立秋",
|
||||
"處暑",
|
||||
"白露",
|
||||
"秋分",
|
||||
"寒露",
|
||||
"霜降",
|
||||
"立冬",
|
||||
"小雪",
|
||||
"大雪",
|
||||
"冬至"
|
||||
]
|
||||
}
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+83
-1
@@ -11,11 +11,17 @@ import {
|
||||
DEFAULT_LANGUAGE
|
||||
} from '@/locales/index.ts';
|
||||
|
||||
import {
|
||||
ALL_LANGUAGES as CHINESE_CALENDAR_ALL_LANGUAGES,
|
||||
DEFAULT_CONTENT as CHINESE_CALENDAR_DEFAULT_CONTENT
|
||||
} from '@/locales/calendar/chinese/index.ts';
|
||||
|
||||
import {
|
||||
TextDirection
|
||||
} from '@/core/text.ts';
|
||||
|
||||
import {
|
||||
type ChineseCalendarLocaleData,
|
||||
CalendarType,
|
||||
CalendarDisplayType,
|
||||
DateDisplayType
|
||||
@@ -26,6 +32,9 @@ import {
|
||||
type DateTimeLocaleData,
|
||||
type TextualYearMonth,
|
||||
type TextualYearMonthDay,
|
||||
type Year1BasedMonth,
|
||||
type YearMonthDay,
|
||||
type CalendarAlternateDate,
|
||||
type DateFormat,
|
||||
type TimeFormat,
|
||||
type LocalizedDateTimeFormat,
|
||||
@@ -178,6 +187,13 @@ import {
|
||||
isPM
|
||||
} from '@/lib/datetime.ts';
|
||||
|
||||
import {
|
||||
type ChineseYearMonthDayInfo,
|
||||
getChineseYearMonthAllDayInfos,
|
||||
getChineseYearMonthDayInfo,
|
||||
getChineseCalendarAlternateDisplayDate
|
||||
} from '@/lib/calendar/chinese_calendar.ts';
|
||||
|
||||
import {
|
||||
appendDigitGroupingSymbolAndDecimalSeparator,
|
||||
parseAmount,
|
||||
@@ -452,6 +468,19 @@ export function useI18n() {
|
||||
return moment.localeData();
|
||||
}
|
||||
|
||||
function getChineseCalendarLocaleData(): ChineseCalendarLocaleData {
|
||||
const localeData = CHINESE_CALENDAR_ALL_LANGUAGES[locale.value] ?? CHINESE_CALENDAR_DEFAULT_CONTENT;
|
||||
const chineseCalendarLocaleData: ChineseCalendarLocaleData = {
|
||||
numerals: localeData['numerals'],
|
||||
monthNames: localeData['monthNames'],
|
||||
dayNames: localeData['dayNames'],
|
||||
leapMonthPrefix: localeData['leapMonthPrefix'],
|
||||
solarTermNames: localeData['solarTermNames']
|
||||
};
|
||||
|
||||
return chineseCalendarLocaleData;
|
||||
}
|
||||
|
||||
function getAllCurrencyDisplayTypes(numeralSystem: NumeralSystem, decimalSeparator: string): TypeAndDisplayName[] {
|
||||
const defaultCurrencyDisplayTypeName = t('default.currencyDisplayType');
|
||||
let defaultCurrencyDisplayType = CurrencyDisplayType.parse(defaultCurrencyDisplayTypeName);
|
||||
@@ -683,7 +712,8 @@ export function useI18n() {
|
||||
return {
|
||||
numeralSystem: numeralSystem,
|
||||
calendarType: calendarType,
|
||||
localeData: getDateTimeLocaleData()
|
||||
localeData: getDateTimeLocaleData(),
|
||||
chineseCalendarLocaleData: getChineseCalendarLocaleData()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1869,6 +1899,56 @@ export function useI18n() {
|
||||
}
|
||||
}
|
||||
|
||||
function getCalendarAlternateDates(yearMonth: Year1BasedMonth): CalendarAlternateDate[] | undefined {
|
||||
const calendarDisplayType = getCurrentCalendarDisplayType().secondaryCalendarType;
|
||||
|
||||
if (!calendarDisplayType) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (calendarDisplayType === CalendarType.Chinese) {
|
||||
const chineseCalendarLocaleData = getChineseCalendarLocaleData();
|
||||
const chineseDates: ChineseYearMonthDayInfo[] | undefined = getChineseYearMonthAllDayInfos(yearMonth, chineseCalendarLocaleData);
|
||||
|
||||
if (!chineseDates) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const ret: CalendarAlternateDate[] = [];
|
||||
|
||||
for (let i = 0; i < chineseDates.length; i++) {
|
||||
const chineseDate = chineseDates[i];
|
||||
const alternateDate = getChineseCalendarAlternateDisplayDate(chineseDate);
|
||||
ret.push(alternateDate);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getCalendarAlternateDate(yearMonthDay: YearMonthDay): CalendarAlternateDate | undefined {
|
||||
const calendarDisplayType = getCurrentCalendarDisplayType().secondaryCalendarType;
|
||||
|
||||
if (!calendarDisplayType) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (calendarDisplayType === CalendarType.Chinese) {
|
||||
const chineseCalendarLocaleData = getChineseCalendarLocaleData();
|
||||
const chineseDate: ChineseYearMonthDayInfo | undefined = getChineseYearMonthDayInfo(yearMonthDay, chineseCalendarLocaleData);
|
||||
|
||||
if (!chineseDate) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return getChineseCalendarAlternateDisplayDate(chineseDate);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getParsedAmountNumber(value: string, numeralSystem?: NumeralSystem): number {
|
||||
const numberFormatOptions = getNumberFormatOptions({ numeralSystem });
|
||||
return parseAmount(value, numberFormatOptions);
|
||||
@@ -2288,6 +2368,8 @@ export function useI18n() {
|
||||
formatUnixTimeToFiscalYear,
|
||||
formatYearToFiscalYear,
|
||||
getTimezoneDifferenceDisplayText,
|
||||
getCalendarAlternateDates,
|
||||
getCalendarAlternateDate,
|
||||
parseAmountFromLocalizedNumerals: (value: string) => getParsedAmountNumber(value),
|
||||
parseAmountFromWesternArabicNumerals: (value: string) => getParsedAmountNumber(value, NumeralSystem.WesternArabicNumerals),
|
||||
formatAmountToLocalizedNumerals: (value: number, currencyCode?: string) => getFormattedAmount(value, undefined, undefined, currencyCode),
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "Gregorian",
|
||||
"Buddhist": "Buddhist"
|
||||
"Buddhist": "Buddhist",
|
||||
"Gregorian with Chinese": "Gregorian with Chinese"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"currency": "CNY",
|
||||
"firstDayOfWeek": "Monday",
|
||||
"fiscalYearFormat": "EndYYYY",
|
||||
"calendarDisplayType": "Gregorian",
|
||||
"calendarDisplayType": "GregorianWithChinese",
|
||||
"dateDisplayType": "Gregorian",
|
||||
"longDateFormat": "YYYYMMDD",
|
||||
"shortDateFormat": "YYYYMMDD",
|
||||
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "公历",
|
||||
"Buddhist": "佛教日历"
|
||||
"Buddhist": "佛教日历",
|
||||
"Gregorian with Chinese": "公历+农历"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"currency": "TWD",
|
||||
"firstDayOfWeek": "Sunday",
|
||||
"fiscalYearFormat": "EndYYYY",
|
||||
"calendarDisplayType": "Gregorian",
|
||||
"calendarDisplayType": "GregorianWithChinese",
|
||||
"dateDisplayType": "Gregorian",
|
||||
"longDateFormat": "YYYYMMDD",
|
||||
"shortDateFormat": "YYYYMMDD",
|
||||
@@ -138,7 +138,8 @@
|
||||
},
|
||||
"calendar": {
|
||||
"Gregorian": "公曆",
|
||||
"Buddhist": "佛曆"
|
||||
"Buddhist": "佛曆",
|
||||
"Gregorian with Chinese": "公曆+農曆"
|
||||
},
|
||||
"datetime": {
|
||||
"AM": {
|
||||
|
||||
Reference in New Issue
Block a user