Files
TREK/client/src/utils/dayAdd.ts
T
Maurice 9a7c17e7cc fix(i18n): a quantity under another name than count is a plural group too
The count-string gate only knew {count} and {n}, the params t() picks a
plural form by. A quantity named anything else kept one form in every
language and passed: Russian read "Все {days} дней" for 2 days and
"{objects} объектов" for 3 objects, Greek "{minutes} λεπτά" for 1 minute.

Twelve such en strings become plural groups with their forms in all 27
locales, the quantity renamed to {count}: the trip length limit, the
chat image limit, the API key limit, the storage move prompt and its
reclaimable line, the Dawarich wish rule and suggestion duration, the
road trip lateness warnings, and the road trip echo and window texts.
Their callers pass the count as a number; the storage panels used to
pass it as a string, which no form is picked by. The reclaimable line
loses its dash for a comma in every locale while it is rewritten.

i18n-parity now treats the quantity names in QUANTITY_PARAMS ({days},
{minutes}, {objects}, {max} and the like) like {count}. The four strings
where the number is followed by nothing but a unit symbol (the Dawarich
durations, the upload size limit) go on NOT_PLURAL with that reason.
2026-10-08 13:04:42 +02:00

38 lines
1.7 KiB
TypeScript

import { MAX_TRIP_DAYS, planDatedAppend } from '@trek/shared'
import type { Day, Trip } from '../types'
type Translate = (key: string, params?: Record<string, string | number>) => string
/**
* What the reorder dialog and the phone's day sheet need to offer adding a day:
* one button for a day without a date, and on a trip with dates a second one for
* the next calendar day. The planner computes it once for both shells.
*/
export interface DayAddControls {
/** The date "Add with date" gives the new day (ISO), or null on a trip without dates, which keeps the single button. */
nextDate: string | null
/** Why no day can be added right now (no connection), or null. */
blocked: string | null
/** Why the dated day in particular cannot be added (the trip is at the day limit), or null. */
datedBlocked: string | null
/** A day is on its way; both buttons wait for it, so a double click adds one day, not two. */
busy: boolean
onAddDated: () => void
}
/**
* The dated half of adding a day: the date the new day would get, and the reason
* it cannot be added when the trip is already at the day limit. The rule is the
* server's own (planDatedAppend), so the button never promises a date the server
* would not give, and never offers a day the server would refuse.
*/
export function datedDayOption(
trip: Pick<Trip, 'start_date' | 'end_date'> | null | undefined,
days: readonly Pick<Day, 'date'>[],
t: Translate,
): Pick<DayAddControls, 'nextDate' | 'datedBlocked'> {
const plan = trip ? planDatedAppend(trip, days.map(d => d.date)) : null
if (!plan) return { nextDate: null, datedBlocked: null }
return { nextDate: plan.date, datedBlocked: plan.fits ? null : t('dashboard.tripTooLong', { count: MAX_TRIP_DAYS }) }
}