Repository navigation
Give slot dates and times a language - #895
Conversation
Part of #620: the core. next-intl and use-intl 4.14.9, pinned together (icu-minify too, through an override), with next.config.mjs wrapped in next-intl's plugin. src/messages/en.json is the English catalog, and next-intl's AppConfig is typed from it, through the declaration the plugin writes, so a missing key or a wrong argument fails typecheck. src/i18n holds the pure locale config (CATALOG_LOCALES, SHIPPED), a synchronous translator on use-intl/core with English filled in under any other language, the server wrapper that logs what goes wrong, the request config the plugin needs, and an English translator for tests that throws. The site footer's labels are the first text in the catalog, so the translator is proven in a server component, on static and dynamic pages. A new check runs it under the worker's toolchain. No page's first-load JavaScript changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A local ESLint plugin in eslint.config.mjs, with one rule so far: opensignup/no-catalogs-in-client. In a file that opens with a 'use client' directive, it reports any import of a catalog in src/messages, or of the translators that load every catalog (src/i18n/translator.ts, server.ts and testing/translator.ts), since either would put that text in the browser's JavaScript. It reads the directive rather than matching paths, follows @/ and relative paths, re-exports, import(), require() and import paths built from a template, and lets type-only imports through, since those are compiled away. The message says why and what to do instead. The tests lint fixtures through the repo's own config, so they also prove the rule is on for the app's files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A unit test over src/messages/ checks every catalog against en.json: completeness per namespace, enforced for each language in SHIPPED for the namespaces its audience reads; every message compiles with icu-minify; placeholders, tags and select branches match English, and each placeholder takes the value English is passed; no key English lacks; and no English message the app doesn't use. Which keys the app uses comes from the type checker: a call whose signature is use-intl's Translator, its namespace from the keys it accepts, its key from the type of its argument, so helpers, props, aliases and typed tables are all seen, and a key or namespace it can't read fails the check. The audience namespaces move from a comment to AUDIENCE_NAMESPACES in src/i18n/config.ts. src/types/next-intl.d.ts imports next-intl, because an augmentation alone doesn't load its module: without it, code with no test importing next-intl typed every message key as a plain string. icu-minify is a devDependency at exactly 4.14.9, the version next-intl and use-intl resolve, and the pnpm override now points at it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Two rules, on only for the files and folders listed in TRANSLATED in eslint.config.mjs, which so far is the site footer: - react/jsx-no-literals with noStrings and ignoreProps, for JSX text; - opensignup/no-literal-text-props, a local rule for a string on aria-label, aria-description, title, placeholder, alt or label. noAttributeStrings would also flag every className and href. TRANSLATED takes paths as they are on disk. filesAt escapes them for the config's globs, since an unescaped src/app/s/[slug]/** matches src/app/s/s/ and not the [slug] folder, and stops lint when a path doesn't exist. The footer's license line is exempt with a comment. Also, from #891's review: no-catalogs-in-client follows a + chain that starts with a string, as it does a template, and denies every module in src/i18n/ to client files except those in CLIENT_SAFE_I18N (config), rather than listing the modules that load catalogs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A translation that kept a select's argument but dropped the select
(`Status: {status}` for English's `{status, select, open {Open} ...}`)
passed, and would show participants the code's value. The check now
reports `{status} isn't a select here, but is in English`.
From the same review:
- The check's program types translators against the en.json it just
loaded, written over src/messages/en.d.json.ts, so a stale declaration
no longer gives misleading lines. findUsedKeys now builds the program
itself, and the fallback for a stale declaration is gone, with its edge
case that could pick the wrong section. messages-declaration.test.ts
still fails on a stale file.
- Code in any `testing` folder and in src/mcp/evals doesn't count as a use.
- `t?.('key')` is seen.
- A test for the dot-in-key check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Turn on next-intl's experimental message precompiling, so the first
client component with translated text ships a small formatter instead of
use-intl's ICU parser: measured here at 3,470 bytes gzipped against
12,353 without it.
Under precompile the plugin's loader compiles every catalog the Next
build imports, the server's too, and a message with an argument, plural
or tag becomes an array. withEnglishUnder treated every object as a
section and went into those arrays, so each such message would have
rendered as its key path in the web process while vitest and the worker,
which read the raw JSON, stayed green. A message is now a string or an
array, and only a section is merged into.
The footer's "{INSTANCE_NAME} · AGPL-3.0" line becomes a message with an
argument, the first the app has, and a production-build e2e checks it on
a prerendered page, a page rendered per request and the public signup
page. A unit test runs next-intl's own loader over every catalog and
checks each message formats the same precompiled as from the raw JSON.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…ext-lint Brings in #892's review fixes (a7a10ed) so this PR stays on top of #892's final state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
formatSlotDate and formatSlotTime now take the reader's language as a
required `locale`, and so does everything that prints a slot's values:
renderFieldValue, slotDetails, summarizeSlotValues, formatGroupLabel,
buildMetaSegments, prettyHeader, and the two commitment services that name a
slot for the edit and cancelled pages. Every caller passes 'en' for now, so
nothing anyone sees changes.
A date is built from its parts as a UTC moment and formatted in UTC, so no
zone can move it to another day. English keeps today's output exactly,
including the hand-written 12-hour clock with its no-break space before
AM/PM; other languages get Intl's own ("lör 3 maj", "18:30" in Swedish).
formatSlotDate now formats only a stored YYYY-MM-DD. It used to fall back to
`new Date()` for any other string, in the host's zone; no caller relied on
that, as both checked isRealDate first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
filesAt escaped the characters a glob reads specially but not the backslash it escapes them with, so a listed folder named `a\b` became the glob `a\b/**`, which matches `ab/` and not `a\b/`. The backslash is now escaped in the same pass as the rest. filesAt takes an optional root so a test can list a real folder with a backslash in its name, made in a temporary directory, and check the glob with ESLint's own matcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…mpile Brings in #893's later commits (#892's final code, main, and the filesAt escaping fix) so this PR stays on top of #893. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…-format Keeps this PR on top of #894's current branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
main now holds #893 (7a9fada), whose final code this branch already had. The only conflict was the footer line #893 exempted from lint and this PR turns into a message; this branch's version is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
…-format Keeps this PR on top of #894's current branch, which now has main (#893) merged in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Tophat: passedRan 86a0365 locally with Test data (made up): "Snack duty — Spring season", grouped by date, with What/Date/Time fields and slots at 12:00 AM (midnight), 12:00 PM, 6:30 PM, 9:05 AM and 11:59 PM, a date-only slot, a slot on 1 Jan, one on a US DST-change day, and one with no date; plus an ungrouped "Carpool" signup whose slots share one date and time; plus a sheet with legacy values in the date field (see the last row).
Also ran the formatter unit tests ( Not checked in the app: the Magic Compose questions also use No visible change, so Generated by Claude Code |
richshaw
left a comment
There was a problem hiding this comment.
Review: passed (round 1)
The PR gives formatSlotDate and formatSlotTime a required locale and passes it through everything that prints a slot's values. Every caller passes 'en', and the commitment services take the locale as a parameter rather than reading it from anywhere. For this part of the issue the PR does what the outline asks, and does it carefully. A date is built with Date.UTC from its validated parts and formatted with timeZone: TIME_ZONE, so the machine's time zone can't move it. (isRealDate refuses years before 1900, which also keeps Date.UTC away from its habit of reading years 0–99 as 1900–1999.) English keeps the hand-written 12-hour clock with its no-break space, and other languages go through Intl.
I compared the old and new English output for every day from 1900 to 2100 and every minute of the day. I also put odd stored values through renderFieldValue: timestamps, typed dates, days that don't exist, years before 1900, numbers and padded strings. I ran all of it with TZ set to UTC, America/Los_Angeles, Pacific/Auckland and Pacific/Kiritimati. All 74,872 outputs matched except one, and that one is a fix. Kiritimati skipped 31 December 1994, so the old code's local midnight rolled over and printed 1994-12-31 as "Sun, Jan 1". The new code prints "Sat, Dec 31".
formatSlotDate now formats only YYYY-MM-DD, and nobody sees a difference:
- its only callers are
renderFieldValueandshare-message.ts, and both already checkedisRealDatefirst; - nothing in
scripts/ortests/calls it; - the tophat put old non-date values into a date field, and both versions show them as typed.
Blocking (0)
Optional (3):
-
localeis a plainstring(src/lib/slot-label.ts:38,57,src/components/build-wysiwyg/prettyHeader.ts:18). That leaves three gaps. None of them can happen while every caller passes'en':- The English clock is used only for exactly
'en'. A regional tag like'en-US'would go toIntland get the runtime's U+202F before PM (Node's does), which is the difference the code comment says this branch avoids. - A malformed tag makes the
Intl.DateTimeFormatconstructor throwRangeErrorin the middle of a render. localenow sits in front ofprettyHeader's optionalfieldLabel, so a call written the old way,prettyHeader(raw, type, label), still type-checks and reads the label as the locale.
Narrowing the type to the catalog's locales once
svjoinsCATALOG_LOCALESwould close all three;resolveLocalein #625 is where the values will come from.stringis right for now, because the Swedish tests couldn't be written againstCatalogLocaleyet. - The English clock is used only for exactly
-
Hydration, for later. Three Build tab components format during render, and they are client components:
TimeSelect,WysiwygSlotandWysiwygGroup(throughprettyHeader). With'en', the server and browser output can't differ: the English time is written out by hand, and the English date already went throughIntlon both sides before this PR. The first PR that passes a signup's language to these components will need to format on the server and pass the text in, or make sure both ICUs agree. #622's "Watch for" section records this. #634, the next issue to touch the Build tab, doesn't mention it. -
The PR body is out of date. It still says Merge after #894 and "Based on #894 … review against that branch". #894 has merged and this PR is now against
main. The merge line no longer holds anything up, but the stack section could say the PR is now onmain.
Earlier threads: none. Copilot couldn't review (out of quota), so this review went ahead without it.
Checks:
- CI is green on 325f17a (run 43536124067: lint, format, typecheck, knip, unit and database tests, build, budgets and e2e, plus CodeQL).
- Tophat: it passed at 86a0365, and that result covers this head. 325f17a, ee870e1 and 86a0365 have the same tree (
7096ee2). The merge ofmainsince then brought in only #894's squash, and the shared check counts 0 runtime hunks since the tophat. - Formatter tests, run locally:
slot-label,slot-summary,prettyHeader,slot-formatandshare-message(119 tests) pass withTZset to UTC, America/Los_Angeles, Pacific/Auckland and Asia/Kolkata. - Time-zone tests: removing
timeZonefrom either formatter makes a test fail ('Fri, Apr 24'for the date,'16:30'for the time), so these tests really check what they claim. - Speed: a quick benchmark shows an English date costs the same as before.
https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Generated by Claude Code
#896 merged, so main now holds this branch's base. The one conflict, src/lib/slot-label.ts, is between #895 and #896 as squashed on main and the same commits in this branch's history; main's copy equals #896's head, so the branch's copy (with TIME_ZONE from its new module) stands. The merged tree is identical to the branch's before the merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
Part of #622: slot dates and times take a language. The other formatters follow in the next PR; the image check is #890.
Merge after #894.
The stack
PR 6 of the localization stack (#619). Based on #894 (
claude/issue-624-precompile); review against that branch.The problem
Every slot date and time is printed in US English:
formatSlotDatenamesen-US, andformatSlotTimewrites a 12-hour clock by hand ("18:30" → "6:30 PM"). A Swedish reader expects "lör 3 maj" and "18:30". The same functions run on the server (public page, Responses tab, emails, the edit and cancelled pages), in the browser (Build tab) and in the worker (reminders), so they need the reader's language passed in before any of those can be translated.The fix
src/lib/slot-label.ts:formatSlotDate(iso, locale)andformatSlotTime(hhmm, locale), withlocalerequired, so TypeScript found every caller.Date.UTCand formatted withtimeZone: TIME_ZONE('UTC', fromsrc/i18n/config.ts, which says why), so neither the server's zone nor the browser's can move it. Before, it was built at local midnight and formatted in the local zone, which agreed but depended on both steps using the same zone.Intlwith'en'(the same pattern asen-US); its time keeps the hand-written 12-hour clock with the no-break space before AM/PM, becauseIntl's English puts a different space there depending on the runtime's ICU (Node's is U+202F).Intl: the date with the sameweekday/month/day: shortoptions, the time withtimeStyle: 'short', which gives each language its own clock ("18:30", and "09:05" rather thanhour: 'numeric''s "9:05" in Swedish).localeand passes it on:renderFieldValue,slotDetails,summarizeSlotValues,formatGroupLabel,buildMetaSegments,prettyHeader(locale before the optional label), and the commitment serviceseditLimitsForCommitmentandcancelledCommitmentState(and their privateslotName), which take it as a parameter.'en'for now:SignupViewBody(once, as a locallocale, threaded throughgroupSlots,nameGroupForandtitleFor),WysiwygSlot,WysiwygGroup, the Responses tab,slotTextfor the emails, and the edit page. Three callers the issue doesn't list:TimeSelect(the Build tab's time picker),share-message.ts(the share panel's dates and time) andbuildMetaSegmentsinslot-format.ts.formatSlotDatenow formats only a stored YYYY-MM-DD and returns null for anything else. It used to fall back tonew Date(iso)for any other string, in the host's zone, which is the zone dependence the issue rules out. No caller relied on it:renderFieldValueandshare-message.tsboth checkedisRealDatefirst, sorenderFieldValueloses its now-redundant check.Checked against the issue
main, so there's no range to format.src/lib/responses-csv.ts) isn't a caller, and isn't touched.fit-text.ts,format-duration.ts, and Magic Compose'sanswers.tsandCompose.tsx. TheDockerfileICU check is Fail the Docker image build when Node lacks full ICU #890.No CHANGELOG entry: nothing anyone sees or sets up changes.
Tests
slot-label.test.ts: the English strings the tests already pinned are unchanged ('Sat, Apr 25','6:30 PM','12:00 AM', …), now with'en'. New: Swedish dates ('lör 3 maj') and times ('18:30','09:05','00:00'), throughformatSlot*,renderFieldValueandslotDetails; impossible dates (2026-02-31,2026-13-01) still null in both languages and shown as typed byrenderFieldValue; a timestamp and a typed "Sat, Nov 14" now null. The existing time-zone test now also checks Swedish underAmerica/Los_AngelesandPacific/Auckland, and a new one checks that times keep their hour under both.slot-summary.test.ts,prettyHeader.test.ts: one Swedish case each, so the locale is shown to reach the formatter.commitments.db.test.ts: a dated slot's name fromeditLimitsForCommitmentin English (Juice · Mon, May 3) and Swedish (Juice · mån 3 maj), and fromcancelledCommitmentStatein Swedish once cancelled.slot-label.tsfor the right reason (English output where Swedish was expected, a timestamp formatted rather than null).Ran in this session, all passing:
pnpm lint,pnpm format:check,pnpm typecheck,pnpm knip,pnpm test(194 files, 2340 tests).TZ=America/Los_AngelesandTZ=Pacific/Aucklandset for the whole run (slot-label,slot-summary,prettyHeader,slot-format,share-message; 119 tests each).pnpm test:db(40 files, 680 tests).pnpm build && pnpm budgets. I also built Precompile the message catalogs at build time #894's head and measured both exactly: every page is within 21 bytes of gzipped first-load JavaScript of before (the Build tab +21,/+16,/s/[slug]and preview +15, the Responses tab −9), so no budget changes.time-format.spec.tsunchanged and passing ("6:30 PM" in the builder and on the public page), pluspublic-commit,edit-token,responses,slot-row-layout,reminder-fieldand the two help walkthroughs that pin dates (create-and-publish-a-signup,take-someone-off-a-slot).Generated by Claude Code