From a176b1c056e9c4be31f8ec2806552c9a57ce77d0 Mon Sep 17 00:00:00 2001 From: zoro Date: Fri, 5 Jun 2026 10:30:36 -0700 Subject: [PATCH] time: use short relative timestamps for french (#168) --- src/shared/components/time.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/shared/components/time.tsx b/src/shared/components/time.tsx index f88226b..11831fe 100644 --- a/src/shared/components/time.tsx +++ b/src/shared/components/time.tsx @@ -29,6 +29,7 @@ const RELATIVE_UNITS: { seconds: number; unit: Intl.RelativeTimeFormatUnit }[] = const LONG_SHORT_TIME_LENGTH = 11; const MIN_SHORT_TIME_SCALE = 0.65; +const SHORT_RELATIVE_TIME_LOCALES = ['fr', 'ru']; export function Time({ date, short, dateOnly, className, longRelativeClassName, shortFitTargetLength, minShortFitScale }: TimeProps) { const dateObj = date == null ? null : new Date(date); @@ -109,7 +110,7 @@ function timeAgo(date: Date, isShort: boolean | undefined, formatters: TimeForma type TimeFormatters = ReturnType; function createTimeFormatters(locale: string) { - const shortRelativeStyle: Intl.RelativeTimeFormatStyle = locale.toLowerCase().startsWith('ru') ? 'short' : 'narrow'; + const shortRelativeStyle: Intl.RelativeTimeFormatStyle = usesShortRelativeTime(locale) ? 'short' : 'narrow'; return { relativeLong: new Intl.RelativeTimeFormat(locale, { numeric: 'always', style: 'long' }), @@ -134,3 +135,8 @@ function createTimeFormatters(locale: string) { }) }; } + +function usesShortRelativeTime(locale: string) { + const normalizedLocale = locale.toLowerCase(); + return SHORT_RELATIVE_TIME_LOCALES.some((shortLocale) => normalizedLocale === shortLocale || normalizedLocale.startsWith(`${shortLocale}-`)); +}