11import { AnimatePresence , m } from 'motion/react'
22import { memo } from 'react'
3+ import { useTranslation } from 'react-i18next'
34
45import { useMobile } from '~/hooks/useMobile'
56import { clsxm } from '~/lib/cn'
@@ -14,6 +15,11 @@ interface DateRangeIndicatorProps {
1415
1516export const DateRangeIndicator = memo (
1617 ( { dateRange, location, isVisible, className } : DateRangeIndicatorProps ) => {
18+ const { t } = useTranslation ( )
19+ const translateDay = ( day : string | number ) => t ( `date.day.${ day } ` as any )
20+ const translateMonth = ( month : string | number ) =>
21+ t ( `date.month.${ month } ` as any )
22+
1723 // 解析日期范围,提取主要的日期信息
1824 const parseMainDate = ( range : string ) => {
1925 // 匹配跨年日期范围格式 "2022年3月 - 2023年5月"
@@ -22,7 +28,8 @@ export const DateRangeIndicator = memo(
2228 )
2329 if ( crossYearMatch ) {
2430 const [ , startYear , startMonth , endYear , endMonth ] = crossYearMatch
25- return `${ startMonth } 月 ${ startYear } – ${ endMonth } 月 ${ endYear } `
31+ // return `${startMonth}月 ${startYear} – ${endMonth}月 ${endYear}`
32+ return `${ translateMonth ( startMonth ) } ${ startYear } - ${ translateMonth ( endMonth ) } ${ endYear } `
2633 }
2734
2835 // 匹配类似 "2022年3月30日 - 5月2日" 的格式
@@ -32,21 +39,24 @@ export const DateRangeIndicator = memo(
3239 if ( singleYearDayMatch ) {
3340 const [ , year , startMonth , startDay , endMonth , endDay ] =
3441 singleYearDayMatch
35- return `${ startMonth } 月${ startDay } 日–${ endMonth } 月${ endDay } 日, ${ year } `
42+ // return `${startMonth}月${startDay}日–${endMonth}月${endDay}日, ${year}`
43+ return `${ translateMonth ( startMonth ) } ${ translateDay ( startDay ) } - ${ translateMonth ( endMonth ) } ${ translateDay ( endDay ) } ${ year } `
3644 }
3745
3846 // 匹配类似 "2022年3月 - 5月" 的格式
3947 const monthRangeMatch = range . match ( / ( \d { 4 } ) 年 ( \d + ) 月 \s * - \s * ( \d + ) 月 / )
4048 if ( monthRangeMatch ) {
4149 const [ , year , startMonth , endMonth ] = monthRangeMatch
42- return `${ startMonth } 月–${ endMonth } 月, ${ year } `
50+ // return `${startMonth}月–${endMonth}月, ${year}`
51+ return `${ translateMonth ( startMonth ) } - ${ translateMonth ( endMonth ) } ${ year } `
4352 }
4453
4554 // 匹配单个日期
4655 const singleDateMatch = range . match ( / ( \d { 4 } ) 年 ( \d + ) 月 ( \d + ) 日 / )
4756 if ( singleDateMatch ) {
4857 const [ , year , month , day ] = singleDateMatch
49- return `${ month } 月${ day } 日, ${ year } `
58+ // return `${month}月${day}日, ${year}`
59+ return `${ translateMonth ( month ) } ${ translateDay ( day ) } ${ year } `
5060 }
5161
5262 // 默认返回原始字符串
0 commit comments