Skip to content

fix(ui): translate the collection label in the create new card button - #17664

Closed
1yakub wants to merge 4 commits into
payloadcms:mainfrom
1yakub:fix/create-new-card-label-translation
Closed

1yakub wants to merge 4 commits into
payloadcms:mainfrom
1yakub:fix/create-new-card-label-translation

Conversation

@1yakub

@1yakub 1yakub commented Aug 5, 2026 •

Copy link
Copy Markdown

The create button on collection cards passes the raw entity label into general:createNewLabel. When a collection has localized labels that label is an object, so the aria-label comes out as "[object Object] neu erstellen", and Button copies aria-label into title so both attributes get it.

Fixed by passing the title that's already translated a few lines up, which is what the showAllLabel call does too. Same change in both widgets: the RSC one and the TanStack Start client one, which carried the same raw label.

Tests: an assertion in test/i18n for the dashboard create button in Spanish (e2e.config.ts mirrors every Next suite into a tanstack-start suite, so it exercises both widgets).

Closes #17069

@1yakub

1yakub commented Aug 14, 2026

Copy link
Copy Markdown
Author

Bump. CI hasn't run here yet, it's waiting on first time contributor workflow approval. The fix is one line, the same getTranslation pattern the neighboring calls in the file already use.

@cbratschi

Copy link
Copy Markdown
Contributor

Thanks for picking this up. The RSC change is correct, but current main also contains packages/ui/src/widgets/CollectionCards/index.client.tsx for TanStack Start, and it has the same raw label interpolation in the create button. Could this PR change that occurrence to label: title as well?

There is already a focused fixture in test/i18n: collection1 has localized labels and the E2E suite switches the admin to Spanish. An assertion on #card-collection1 .card__actions a for both aria-label and title would cover the regression. Running the suite for Next.js and TanStack Start would exercise both implementations.

I confirmed that both files on current main still pass the raw label.

@cbratschi

Copy link
Copy Markdown
Contributor

Verified on current main: this PR fixes the collection-card occurrence. The same raw localized label is still interpolated in DocumentDrawerToggler, affecting both the “Add new” and “Edit” accessible names.

Would you prefer to include that occurrence here? I can prepare the source change plus a focused accessibility assertion, or keep it as a separate PR.

@1yakub

1yakub commented Sep 4, 2026

Copy link
Copy Markdown
Author

Yes, makes sense to keep them together. Pushed 4f695c7: DocumentDrawerToggler now runs the singular label through getTranslation with i18n, same as the card, so the Add new and Edit accessible names read localized too. Not built locally on this machine, CI has it.

@cbratschi

Copy link
Copy Markdown
Contributor

Thanks, the drawer change matches the fix in #17959, where I also added a localized-label fixture and an accessibility regression test verified on localhost. Those test changes can be included here so we can consolidate the PRs.

One occurrence remains: packages/ui/src/widgets/CollectionCards/index.client.tsx still passes the raw label to createNewLabel. That needs label: title too, as mentioned earlier.

The latest CI run is currently marked action_required, so it still needs workflow approval before the build and tests can run.

…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

1yakub commented Sep 23, 2026

Copy link
Copy Markdown
Author

Sorry for the wait on this one. Pushed the remaining piece: index.client.tsx now passes label: title too, so all three spots go through getTranslation.

Pulled your test changes in as well: the Relation One localized labels on the fixture and the drawer toggler aria-label test in fields-relationship, same placement as #17959. The i18n suite also carries the Spanish assertion on the dashboard create button (#card-collection1 .card__actions a), which fails with Crear [object Object] when the widget fix is reverted.

Happy to consolidate here, or to drop my drawer commit in favor of #17959 if you'd rather keep the test where you wrote it. Whichever is less work for you.

@cbratschi

Copy link
Copy Markdown
Contributor

Thanks. Since #17959 is already open, mergeable, and has the focused drawer regression test, I would prefer keeping the fixes split by component: #17664 for both CollectionCards implementations and the dashboard i18n regression, and #17959 for DocumentDrawerToggler with the localized relationship fixture and accessibility test.

Please drop the drawer-related change and test from this PR. That avoids duplication while keeping both PRs focused. Thanks for offering both options.

Kept split by component per review: the drawer toggler fix, the localized
relationship fixture and the accessibility test live in payloadcms#17959.
@1yakub

1yakub commented Sep 23, 2026

Copy link
Copy Markdown
Author

Done, dropped the drawer change and test.

@GermanJablo

Copy link
Copy Markdown
Contributor

Thanks for the thorough work here! main already includes this fix via #18358, so I ported your change and test to 3.x in #19116 (with you as co-author). Closing this one in favor of that.

GermanJablo added a commit that referenced this pull request Oct 27, 2026
… (3.x) (#19116)

### What?

Port of #17664 to `3.x`. The create button on the dashboard collection
cards now passes the translated collection label to
`general:createNewLabel`.

### Why?

With localized collection labels (for example `{ en: 'Pages', de:
'Seiten' }`), the raw label object was interpolated, so the button's
`aria-label` and `title` read `[object Object] neu erstellen`. Reported
in #17069 and confirmed on 3.85.1, 3.85.2 and 3.88.0.

`main` already includes this fix via #18358.

### How?

- Use the already translated `title` in the create button's
`aria-label`, matching the `showAllLabel` call above it.
- Add the `test/i18n` e2e assertion from #17664 for both `aria-label`
and `title`. It fails without the fix (`Received: "Crear [object
Object]"`) and passes with it.
- The pre-commit hook also sorted the existing imports in
`test/i18n/e2e.spec.ts`.

Thanks to @1yakub for the original fix and test, and to @cbratschi for
the report and review.

Fixes #17069

Co-authored-by: German Jablonski <[email protected]>
Co-authored-by: Yakub Hossain <[email protected]>
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.

Card button aria-label and title not correctly localized

3 participants