feat: allow overriding default English labels in admin bar#16615
Open
Zayooo00 wants to merge 1 commit into
Open
feat: allow overriding default English labels in admin bar#16615Zayooo00 wants to merge 1 commit into
Zayooo00 wants to merge 1 commit into
Conversation
Adds an optional `labels` prop to `PayloadAdminBar` that lets consumers
swap any of the hardcoded English strings rendered inside the bar:
- `edit`: text on the Edit link (default `Edit <singular>` / `Edit page`)
- `create`: text on the Create link (default `New <singular>` / `New page`)
- `exitPreview`: text on the preview-exit button (default `Exit preview mode`)
- `logout`: text on the Logout link (default `Logout`)
- `profile`: fallback shown when the user has no email (default `Profile`)
`edit` and `create` accept either a string or a function
`(args: { singular?: string }) => string`, so consumers using a localized
`collectionLabels.singular` can interpolate it into the translated label.
Defaults are unchanged, so existing consumers see no behavior change.
Adds a Customizing labels section to the README with a Polish example.
796df50 to
9941097
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The admin bar currently renders five hardcoded English strings inside the bar (
Edit <singular>,New <singular>,Exit preview mode,Logout,Profile). There is no API for swapping them out short of forking the package, which makes the bar awkward for any site that runs in another language or wants different copy.This PR adds an optional
labelsprop toPayloadAdminBarthat lets consumers override each of those strings individually:Shape
editandcreateaccept either a plain string or a function. The function form receives the resolvedcollectionLabels.singularso the consumer can localize while still pulling the collection name into the label.Backwards compatibility
No behavior change for existing consumers. All five fallbacks match the strings that were hardcoded before.
Notes
Customizing labelssection and a Polish usage example.pnpm exec tsc --noEmit.If you'd prefer a different API shape (e.g. a flat
editLabel/createLabelrather than a groupedlabelsobject), happy to revise.