@@ -10,6 +10,7 @@ import { conId, conName, conTimeZone } from '@/configuration'
1010import { useCache } from '@/context/data/Cache'
1111import { EventDayRecord } from '@/context/data/types.api'
1212import { useNow } from '@/hooks/time/useNow'
13+ import { dateFnsLocales } from '@/i18n'
1314import { parseDefaultISO } from '@/util/parseDefaultISO'
1415
1516import { Image } from '../generic/atoms/Image'
@@ -36,7 +37,7 @@ const isSameDayInTimezone = (date1: Date, date2: string, timezone: string) => {
3637/**
3738 * Calculates the countdown title based on current time and event days.
3839 */
39- const useCountdownTitle = ( t : TFunction , now : Date ) => {
40+ const useCountdownTitle = ( t : TFunction , now : Date , currentLanguage : string ) => {
4041 const { eventDays } = useCache ( )
4142 const firstDay = eventDays [ 0 ]
4243 const lastDay = eventDays [ eventDays . length - 1 ]
@@ -49,7 +50,8 @@ const useCountdownTitle = (t: TFunction, now: Date) => {
4950 if ( firstDay ) {
5051 const firstDate = new Date ( firstDay . Date )
5152 if ( now < firstDate ) {
52- const diff = formatDistance ( firstDate , now )
53+ const locale = dateFnsLocales [ currentLanguage as keyof typeof dateFnsLocales ] || dateFnsLocales . en
54+ const diff = formatDistance ( firstDate , now , { locale, addSuffix : true } )
5355 return t ( 'before_event' , { conName, diff } )
5456 }
5557 }
@@ -66,13 +68,13 @@ const useCountdownTitle = (t: TFunction, now: Date) => {
6668}
6769
6870export const CountdownHeader : FC < CountdownHeaderProps > = ( { style } ) => {
69- const { t } = useTranslation ( 'Countdown' )
71+ const { t, i18n } = useTranslation ( 'Countdown' )
7072 const { t : tAccessibility } = useTranslation ( 'Home' , { keyPrefix : 'accessibility' } )
7173 const isFocused = useIsFocused ( )
7274 const now = useNow ( isFocused ? 60 : 'static' ) // Convert to Date
7375
7476 const { width } = useWindowDimensions ( )
75- const subtitle = useCountdownTitle ( t , now )
77+ const subtitle = useCountdownTitle ( t , now , i18n . language )
7678
7779 return (
7880 < View style = { [ styles . container , style ] } role = "banner" accessibilityLabel = { tAccessibility ( 'countdown_header' ) } accessibilityHint = { tAccessibility ( 'countdown_header_hint' ) } >
0 commit comments