Skip to content

fix(i18n): every date branch threads the active locale — future-relative and absolute forms localize (#4468) - #4512

Merged
yinlianghui merged 1 commit into
mainfrom
claude/issue-4468-date-locale-census
Aug 13, 2026
Merged

fix(i18n): every date branch threads the active locale — future-relative and absolute forms localize (#4468)#4512
yinlianghui merged 1 commit into
mainfrom
claude/issue-4468-date-locale-census

Conversation

@yinlianghui

Copy link
Copy Markdown
Collaborator

Closes #4468

On a zh session the same task row rendered 逾期 6 天 in one column and In 3 days in the next, with the datetime column reading 8/11/2026 12:00 am. Not a missing translation — a second locale channel that nobody was following.

1. Census — every date-formatting site the affected surfaces reach

The console list / all-views pages render date columns through getCellRenderer('date' | 'datetime') in @object-ui/fields; the same records' detail and form faces go through the read-only field widgets. Column 3 is the locale each site threaded before this PR.

# Site Branch Locale threaded before Disposition
1 packages/fields/src/index.tsx:824 DateCellRenderer relative past, relative future, near-today, and the beyond-±7d absolute fallback useLocalization().locale — the tenant default only, undefined on an unconfigured workspace fixed
2 packages/fields/src/index.tsx:866 DateTimeCellRenderer absolute date + time none at all — both calls passed undefined fixed
3 packages/fields/src/widgets/DateField.tsx:17 (readonly) absolute date none fixed
4 packages/fields/src/widgets/DateTimeField.tsx:17 (readonly) absolute date + time none fixed
5 packages/fields/src/widgets/FormulaField.tsx:14 (return_type: 'date') absolute date none fixed
6 packages/fields/src/widgets/GridField.tsx:400 sub-grid temporalText / displayText absolute date, datetime none fixed
7 packages/fields/src/index.tsx:506 formatRelativeDays relative, both directions options.locale — already correct unchanged (it was never the defect; its caller was)
8 packages/fields/src/index.tsx:555 formatDate default branch absolute options.locale — already correct unchanged (same: fixed by site 1)
9 the overdue phrase, fields.relativeDate.overdue relative past, due-like options.t → the ACTIVE UI language unchanged — this is the half that always worked
10 packages/fields/src/index.tsx:562 formatDate 'short' branch absolute hardcoded 'en-US' reported, not fixed — see §5
11 packages/fields/src/index.tsx:588 formatDateTime absolute none, and no parameter to give it one reported, not fixed — see §5
12 packages/fields/src/widgets/RecordPickerDialog.tsx:863 $date fallback absolute none reported, not fixed — see §5

The mechanism the census exposes

There are two locale channels, and each half of a row was reading a different one:

  • the overdue phrase resolves through useFieldTranslate() → the active UI language逾期 6 天;
  • every Intl branch took its tag from useLocalization().locale — the tenant's regional default (ADR-0053), which is undefined on any workspace that never configured one. Intl reads undefined as the machine's locale, so those branches rendered en-US beside the Chinese one. A language switch moves the i18next instance and never touches that channel, which is why switching to Chinese fixed the labels and not the dates.

2. One resolver

useDisplayLocale() in @object-ui/i18n already composes both channels with a documented precedence — tenant regional default → active UI language → 'en' — and is already what every number and currency renderer uses. Every site above now resolves through it, so a date and the number beside it can no longer disagree.

Measured before adopting it, as the ruling asked:

  • The 'zh' ↔ BCP-47 mapping lives in exactly one place, and that place is this hook — because no mapping is needed. The UI language codes this renderer ships ('zh', 'ja', 'de', …) are already well-formed BCP-47 language subtags, so Intl accepts them verbatim: Intl.RelativeTimeFormat('zh', { numeric: 'auto' }).format(3, 'day') is 3天后, identical to what 'zh-CN' produces. There is no table to centralize and none was added. The card's note that 'zh-CN' is rejected by isKnownLanguage() is about the language channel's input, not about what Intl is handed.
  • The mechanism the localized half already used is the one that survives. formatRelativeDays was already Intl.RelativeTimeFormat; the overdue phrase was already t(). Neither moved. The change is entirely in which tag reaches the first one.
  • Blast radius, measured before moving anything. useDisplayLocale() is a hook, so each of the six sites had to be a component that could call it — all six are. No call site moved between modules, no exported signature changed, and the two module-private helpers that gained a locale parameter (temporalText, displayText) have three call sites, all inside GridField itself.
  • Existing pins moved: two, deliberately. GridField.test.tsx pinned its temporal expectations with bare toLocaleDateString() / toLocaleTimeString() — i.e. against the machine. They agreed with the widget only because the runner is en-US, and they would have kept agreeing after the widget started following the session, which is precisely the bug they now need to be able to see. They are spelled 'en' now — the value useDisplayLocale() resolves to with no provider — so the pin states what it means. No other existing expectation changed.

3. Red-first, per measured branch

Captured verbatim from the run against unmodified renderers, then re-measured after. Every zh case below was red before and green after; the reverse verification (reverting the five source files onto origin/main while keeping the tests) turns exactly these eight red again and nothing else.

Branch Before (verbatim) After
future-relative In 3 days 3天后
past-relative, non-due 6 days ago 6天前
near-today Today 今天
absolute, beyond ±7d Sep 12 9月12日
absolute datetime 8/11/2026 + 12:00 am 2026/8/11 + 上午12:00
readonly DateField 8/11/2026 2026/8/11
sub-grid read-only cell 6/17/2026 2026/6/17
formula field, date 8/11/2026 2026/8/11

4. Must-not-change — green on both sides

  • English is byte-identical. In 3 days, 6 days ago, Today, Tomorrow, Yesterday, 8/11/2026, 12:00 am — asserted as literals, and green before and after. 'en' and the runner's en-US agree on every one of these forms, which is why this is a pin rather than a hope.
  • The already-localized past/overdue branch is undisturbed: 逾期 6 天 (zh) and Overdue 6d (en) still resolve through t(), not through Intl, and the overdue cell keeps its text-red-600.
  • Channel precedence is unchanged: an explicit tenant locale still outranks the active UI language (zh chrome + tenant enIn 3 days).
  • .d.ts is byte-identical. packages/fields/dist/index.d.ts hashes f69dd0821892347bc4f8d69951ed587580046ec5ae043f1f0b8cb960853cb54f both before and after — no public surface grew, hence patch and not minor. @object-ui/i18n's diff is comment-only (a docstring in useDisplayLocale claimed DateCellRenderer "already formats from this channel" — the one thing that was not true).

One test expectation I wrote had to be withdrawn rather than made to pass, and it is worth recording: a provider-less case asserting the 'en' last resort cannot live in the new file. useObjectTranslation() outside a provider reports i18n.language from react-i18next's global instance, and every I18nProvider mounted above leaves that global on the language it was given — so a provider-less render placed after the zh cases resolves zh, and the assertion would have been about test ordering, not about the fallback. That pin lives in DateCellRenderer.test.tsx, which mounts no provider at all, and both files now say so. Filed as a repo-wide trap in the findings below.

5. Census sites deliberately NOT fixed here

  • Site 10, formatDate(…, 'short')'s hardcoded 'en-US' — its only consumers are plugin-grid/src/ObjectGrid.tsx:2778,2795, which is the ⛔ in-flight Cross-page select-all fan-out ignores the view's query under external pagination — lastFindParamsRef and the query-change reset are written only by ObjectGrid's own loader #4501 surface, and neither call site threads a locale at all. Changing the fields half alone would move nothing for any current caller; the fix has to land on both halves at once.
  • Site 11, formatDateTime — takes no options parameter, so no caller can localize it. Its only in-repo consumers are plugin-gantt/src/ObjectGantt.tsx:648,655 (and 646,653 for formatDate), which is neither a measured surface nor covered by this card's scope; adding a parameter here with nothing passing it would grow the public surface for no consumer.
  • Site 12, RecordPickerDialog's $date fallback — a MongoDB-shaped value in a lookup picker column, reachable by no test in the repo.

All three are recorded on #4272 (see below) rather than fixed on a rider.

6. Note for triage — #4272 looks like this card's twin

#4272 is open, pm:queue, undispatched, and describes the same defect from the same QA run (objectstack-ai/objectstack#7640). Its comment thread independently predicted the exact root cause measured here — DateCellRenderer reading channel 1 only, useDisplayLocale() as the resolver. This PR does not close it: #4272's stated root cause also names formatDateTime's missing parameter, which is site 11 above and is left alone on purpose. Flagging for the PM to dedupe rather than acting on it.

Verification

pnpm exec vitest run packages/fields/                       → 85 files, 1348 tests, all passed
pnpm exec vitest run packages/plugin-{grid,list,detail,form,gantt,kanban,calendar,timeline}/ \
                     packages/mobile/ packages/i18n/        → 324 files, 3620 tests, all passed
pnpm exec vitest run packages/{components,react,collaboration}/ → 166 files, 1709 tests, all passed
pnpm exec vitest run packages/app-shell/                    → 363 files, 3492 passed, 1 skipped
pnpm exec turbo run type-check --filter='...@object-ui/fields'  → 54/54 successful
      (prefix filter = the DOWNSTREAM consumers of @object-ui/fields)
pnpm exec turbo run lint --filter=@object-ui/fields --filter=@object-ui/i18n → 0 errors
node scripts/check-control-bytes.mjs                        → OK (4218 files)
node scripts/check-changeset-presence.mjs / -no-major / -fixed → all OK

Reverse verification: git checkout origin/main -- the five source files, tests kept → 8 failed | 1340 passed, the eight being exactly the zh rows in §3.


Generated by Claude Code

Date rendering had two locale channels and only one followed the user's
language: the overdue phrase resolved through the translate fn (active UI
language) while every Intl branch read the raw tenant locale, which is
undefined on an unconfigured workspace — and undefined means the MACHINE's
locale. So one row showed 逾期 6 天 beside In 3 days, and datetime columns
rendered 8/11/2026 12:00 am on a zh session.

Every date-formatting site in @object-ui/fields now resolves through the
existing useDisplayLocale() channel (tenant locale -> active UI language ->
en): DateCellRenderer, DateTimeCellRenderer, the read-only DateField /
DateTimeField / FormulaField faces, and the sub-grid's temporal cells.
English output is byte-identical and the overdue wording is untouched.

No public signature changed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Qqyix2QcnpUC9XeYVDzx3
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Aug 13, 2026 2:59am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Main entry (gzip) 24.7 KB 350 KB
Entry file index-CJ_ZUBa0.js
Status PASS

📦 Bundle Size Report

Package Size Gzipped
app-shell (index.js) 9.56KB 3.59KB
app-shell (runtime-config.js) 7.42KB 2.32KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 8.92KB 3.41KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 1.17KB 0.53KB
auth (AuthProvider.js) 25.13KB 5.40KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.13KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.64KB 2.21KB
auth (SocialSignInButtons.js) 9.60KB 3.89KB
auth (UserMenu.js) 3.40KB 1.22KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 38.46KB 10.17KB
auth (createAuthenticatedFetch.js) 6.34KB 2.43KB
auth (index.js) 2.35KB 1.07KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 5.02KB 0.88KB
auth (useIsWorkspaceAdmin.js) 1.61KB 0.85KB
collaboration (CommentThread.js) 26.07KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.65KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 489.32KB 108.45KB
core (index.js) 3.37KB 1.34KB
create-plugin (index.js) 10.08KB 3.26KB
data-objectstack (index.js) 153.79KB 41.35KB
fields (index.js) 230.14KB 57.12KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (currency.js) 1.22KB 0.64KB
i18n (i18n.js) 4.32KB 1.77KB
i18n (index.js) 3.35KB 1.38KB
i18n (pickLocalized.js) 3.69KB 1.73KB
i18n (provider.js) 23.12KB 7.62KB
i18n (useDisplayLocale.js) 2.84KB 1.45KB
i18n (useObjectLabel.js) 27.59KB 6.63KB
i18n (useSafeTranslation.js) 7.77KB 3.13KB
layout (index.js) 38.98KB 10.85KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.74KB
mobile (index.js) 1.50KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.71KB 0.42KB
mobile (useResponsiveConfig.js) 1.36KB 0.63KB
mobile (useSpecGesture.js) 4.32KB 1.64KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 8.75KB 3.06KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 3.67KB 1.12KB
permissions (evaluator.js) 4.41KB 1.44KB
permissions (index.js) 0.91KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.52KB
permissions (usePermissions.js) 1.55KB 0.71KB
plugin-ai (index.js) 15.75KB 3.80KB
plugin-calendar (index.js) 46.86KB 12.91KB
plugin-charts (index.js) 62.07KB 17.65KB
plugin-chatbot (index.js) 181.21KB 43.14KB
plugin-dashboard (index.js) 120.95KB 31.53KB
plugin-designer (index.js) 212.58KB 42.83KB
plugin-detail (index.js) 239.03KB 59.77KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 114.58KB 27.68KB
plugin-gantt (index.js) 164.14KB 39.98KB
plugin-grid (index.js) 188.40KB 50.10KB
plugin-kanban (index.js) 48.62KB 13.42KB
plugin-list (index.js) 111.13KB 27.12KB
plugin-map (index.js) 18.16KB 5.81KB
plugin-markdown (index.js) 13.72KB 4.69KB
plugin-report (index.js) 41.16KB 10.96KB
plugin-timeline (index.js) 26.21KB 7.52KB
plugin-tree (index.js) 8.50KB 2.88KB
plugin-view (index.js) 84.08KB 20.55KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.71KB 3.53KB
providers (index.js) 0.44KB 0.22KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.67KB 2.37KB
react (LazyPluginLoader.js) 3.77KB 1.33KB
react (SchemaRenderer.js) 23.73KB 7.96KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 1.23KB 0.66KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 4.09KB 1.74KB
sdui-parser (index.js) 4.47KB 2.03KB
sdui-parser (parse.js) 10.04KB 2.82KB
sdui-parser (types.js) 0.29KB 0.24KB
sdui-parser (validate.js) 4.69KB 1.48KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 0.20KB 0.18KB
types (crud.js) 0.20KB 0.18KB
types (dashboard-filter-alias.js) 6.23KB 2.74KB
types (data-display.js) 0.20KB 0.18KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.87KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-retry.js) 4.32KB 2.02KB
types (index.js) 3.05KB 1.52KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 2.59KB 1.31KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 0.20KB 0.18KB
types (ui-action.js) 3.40KB 1.71KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dates are half-localized on a zh-CN session — past-relative forms translate, future-relative forms and absolute timestamps stay en-US, on the same row

2 participants