-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Allow resource specific translations for pages and buttons #10686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
I'm a bit worried by the fact that the resource-specific translation keys for the CreateButton and the Create pages are the same. In my opinion, users should be able to have different translations for those (e.g. "Create" for the button and "New post" for the page). |
They're not the same. One is |
<CreateButton>
@@ -63,6 +64,14 @@ const CreateButton = (inProps: CreateButtonProps) => { | |||
}); | |||
const createPath = useCreatePath(); | |||
const translate = useTranslate(); | |||
const getResourceLabel = useGetResourceLabel(); | |||
const label = | |||
labelProp ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression: if a user provides a custom label, it is no longer translated. Same for the other buttons.
translate(`resources.${resource}.action.delete`, { | ||
recordRepresentation, | ||
_: translate(`ra.action.delete`, { | ||
name: getResourceLabel(resource, 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've computed a better resourceName
just above, use it instead of this one.
@@ -77,6 +84,15 @@ export const DeleteWithConfirmButton = <RecordType extends RaRecord = any>( | |||
if (isValidElement(recordRepresentation)) { | |||
recordRepresentation = `#${record?.id}`; | |||
} | |||
const label = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression: the label will be translated twice, because it's already translated by Button
. Same for the other buttons.
Problem
We have many translations that receive (or should receive) the current resource, for instance:
ra.page.create
(and other similar views)ra.action.create
(and other similar actions)However, in some languages such as French, some words are feminine and other masculine. This forces devs to have their own translations if they want:
Solution
Just like we did for notifications, accept resource specific translations in the form:
resources.posts.page.create
resources.posts.action.create
Those translations should fall back to the current translations.
I identified the following translations but there may be others:
How To Test
Additional Checks
master
for a bugfix or a documentation fix, ornext
for a featureAlso, please make sure to read the contributing guidelines.