Skip to content

fix(ui): translate document drawer labels - #17959

Merged
GermanJablo merged 3 commits into
payloadcms:mainfrom
cbratschi:codex/fix-document-drawer-localized-label
Oct 29, 2026
Merged

GermanJablo merged 3 commits into
payloadcms:mainfrom
cbratschi:codex/fix-document-drawer-localized-label

Conversation

@cbratschi

Copy link
Copy Markdown
Contributor

What?

Translate localized collection labels before interpolating them into DocumentDrawerToggler accessible names.

Add an E2E regression using a localized singular label and verify that the relationship add-new button exposes Add new Relation One instead of Add new [object Object].

Why?

DocumentDrawerToggler passes collectionConfig.labels.singular directly to i18next. When the label is a localized object, the generated aria-label contains [object Object]. The accessible name then overrides the correctly translated visible button text for screen-reader users.

This addresses the additional DocumentDrawerToggler occurrence reported in #17069. The original CollectionCards occurrence remains separate.

How?

Resolve the collection label with getTranslation and the active i18n instance before calling t. The relationship fixture now uses a localized label so the Playwright assertion exercises the real configuration shape.

Validation:

  • focused Playwright regression test against SQLite and system Chrome
  • focused ESLint (no errors; pre-existing warnings only)
  • Prettier
  • git diff --check

1yakub added a commit to 1yakub/payload that referenced this pull request Sep 23, 2026
…idget

The client widget passed the same raw label object to createNewLabel as the RSC
widget did. Adds the i18n e2e assertion on the dashboard create button, and the
localized label fixture plus the drawer toggler aria-label test from payloadcms#17959 so the
two PRs can be consolidated here.
1yakub added a commit to 1yakub/payload that referenced this pull request Sep 23, 2026
Kept split by component per review: the drawer toggler fix, the localized
relationship fixture and the accessibility test live in payloadcms#17959.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6ba30ed and 351b161.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8fe1a0f and 6ba30ed.

Files selected for processing: 3
  • packages/ui/src/elements/DocumentDrawer/index.tsx
  • test/fields-relationship/collections/Relation1/index.ts
  • test/fields-relationship/e2e.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The relationship create-document drawer trigger now uses the translated singular collection label in its accessible label. The relationship end-to-end test verifies the label “Add new Relation One.”

Changes: Drawer accessible label

Layer / File(s) Summary
Resolve and verify the singular label
packages/ui/src/elements/DocumentDrawer/index.tsx, test/fields-relationship/collections/Relation1/index.ts, test/fields-relationship/e2e.spec.ts
DocumentDrawerToggler resolves the singular collection label before using it in the translated aria label. The relationship fixture adds singular and plural labels, and the end-to-end test checks for “Add new Relation One.”

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • payloadcms/payload#17069: Reports the same localized-label interpolation defect in another admin control. This change fixes the DocumentDrawerToggler occurrence; the CollectionCards occurrence remains out of scope.

Possibly related PRs

Merge Risk: Minimal · previous review 6ba30

The localized accessible-name change is supported by the source contracts and regression coverage, with no remaining merge-blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description clearly explains the localized label issue, the implementation, the regression test, and the validation performed. It directly matches the changeset.
Title check Passed The title clearly and concisely identifies the main change: translating document drawer labels in the UI.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches: 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@GermanJablo GermanJablo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@GermanJablo
GermanJablo enabled auto-merge (squash) October 28, 2026 17:14
GermanJablo added a commit that referenced this pull request Oct 28, 2026
### What?

Port of #17959 to `3.x`. `DocumentDrawerToggler` now passes the
translated collection label to `fields:addNewLabel` and
`general:editLabel`.

### Why?

With localized collection labels (for example `{ en: 'Pages', de:
'Seiten' }`), the raw label object was interpolated, so the toggler's
`aria-label` read `Add new [object Object]`. The accessible name
overrides the correctly translated visible text for screen reader users.
Reported in #17069, alongside the collection card occurrence fixed in
#19116.

### How?

- Resolve `collectionConfig.labels.singular` with `getTranslation`
before calling `t`, matching #17959.
- Give the `relation-one` fixture localized labels and add an e2e test
that the relationship add-new button exposes `Add new Relation One`.

Co-authored-by: German Jablonski <[email protected]>
Co-authored-by: Christoph Bratschi <[email protected]>
@GermanJablo
GermanJablo merged commit 96bc50e into payloadcms:main Oct 29, 2026
291 checks passed
GermanJablo added a commit that referenced this pull request Oct 30, 2026
…9208)

### What?

Fixes every remaining place where a config label (a locale record or
label function) or another non-primitive value is interpolated into a
string without being resolved first.

User-visible fixes:

- **Group by button** showed `Group by [object Object]` for fields
nested in a group or named tab, because `ReducedField.label` holds JSX
there. It now uses `plainTextLabel`. `reduceFieldsToOptions` also falls
back to the humanized field name for `label: false` fields, as
`combineFieldLabel` already does, so the button no longer reads `Group
by Meta > `.
- **Number `hasMany` min/max errors** interpolated the whole array
(`1,2,30 is greater than the max allowed value of 10`). They now name
the offending number.
- **Config errors** (`DuplicateGlobal`, `InvalidFieldName`,
`InvalidFieldRelationship`, `MissingFieldInputOptions`,
`ReservedFieldName`) and the **cloud-storage / payload-cloud delete
error logs** printed `[object Object]` or the source of a label
function. They now fall back to the field name or slug when the label is
not a plain string, which matches the existing pattern in
`saveVersion.ts`.
- `LinkEditor` was passing `i18n` as interpolation variables to `t()`.

### Why?

Follow-up to
[#19198](#19198),
[#17959](#17959) and
[#18358](#18358). These bugs
keep coming back one at a time because `TFunction` accepts `options?:
Record<string, any>`, and the runtime stringifies each value, so objects
become `[object Object]`.

### How?

- I found the sites by temporarily narrowing `TFunction` to primitive
values and running `tsc -b`, then running a TypeScript compiler-API
audit for what the compiler can't see: `any` values, labels in template
literals, and `aria-label`, `title`, `placeholder` and `alt` attributes
across all packages. The remaining hits are counts, filenames, document
titles and GraphQL type names.
- The `TFunction` type is unchanged. Narrowing it would stop correct
code from compiling (for example booleans or `Date` values, which the
runtime stringifies fine), which is a breaking change under the
[versioning
policy](https://github.com/payloadcms/payload/blob/main/docs/migration-guide/versioning.mdx).

Tests:

- Unit test for the `hasMany` number message.
- e2e tests for the Group by button with a nested field and with a
nested `label: false` field. The first fails on `main` with `Group by
[object Object]`.
- e2e test for the sort button labels with a locale-record field label.

3.x port: [#19209](#19209)

---------

Co-authored-by: German Jablonski <[email protected]>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 This is included in version v4.0.0-beta.7

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants