Skip to content

Fix inspector editors ignoring the ra.configurable translations - #11468

Open
farisbasha wants to merge 2 commits into
marmelab:masterfrom
farisbasha:fix-inspector-i18n-keys
Open

farisbasha wants to merge 2 commits into
marmelab:masterfrom
farisbasha:fix-inspector-i18n-keys

Conversation

@farisbasha

Copy link
Copy Markdown
Contributor

Problem

The inspector editors use translation keys that do not exist:

  • DatagridEditor, SimpleFormEditor and SimpleListEditor call useSetInspectorTitle('ra.inspector.Datagrid.title' | 'ra.inspector.SimpleForm.title' | 'ra.inspector.SimpleList.title', ...)
  • FieldsSelector translates its buttons with ra.inspector.hideAll and ra.inspector.showAll

These messages are defined under ra.configurable.* (ra.configurable.Datagrid.title, ra.configurable.SimpleForm.title, ra.configurable.SimpleList.title, ra.configurable.inspector.hideAll, ra.configurable.inspector.showAll) in TranslationMessages, ra-language-english and ra-language-french. No ra.inspector section exists in any of them.

In English the _ fallback text matches, so nothing looks wrong. With any other language, the inspector title and the "Hide All" / "Show All" buttons stay in English. For example, with ra-language-french they show "Datagrid" and "Hide All" instead of "Tableau" and "Masquer tout".

Solution

Use the existing ra.configurable.* keys. The English fallbacks (_) are unchanged, so English apps render the same text as before.

How To Test

Added a unit test in SimpleFormConfigurable.spec.tsx. It renders the Basic story with an i18nProvider that only knows the ra.configurable.* messages, opens the SimpleForm editor, and checks that the translated title and Hide/Show All labels are shown. Without the fix, the editor asks for the ra.inspector.* keys, so this provider returns the English fallback and the test cannot find the translated text.

Manual check: use polyglotI18nProvider with ra-language-french, enable the configure mode on a <DatagridConfigurable>, and open the column editor. The inspector should show "Tableau" with "Masquer tout" / "Afficher tout".

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why): not needed, the existing SimpleFormConfigurable / DatagridConfigurable stories already show these editors
  • The documentation is up to date

I prepared this with an AI assistant. I verified it by reading the code, comparing the keys with TranslationMessages and the language packages, and syntax-checking the changed files. I did not run the test suite locally, so CI will be the test run.

The Datagrid, SimpleForm and SimpleList editors set their inspector title
with ra.inspector.*.title keys, and FieldsSelector translated its buttons
with ra.inspector.hideAll / ra.inspector.showAll. None of these keys exist
in the translation messages: they are defined under ra.configurable.* in
TranslationMessages and in every language package. The English fallback
hid the problem, but non-English apps showed the English text.
Comment on lines +48 to +75
describe('i18n', () => {
it('should translate the inspector title and buttons with the ra.configurable messages', async () => {
const messages: Record<string, string> = {
'ra.configurable.SimpleForm.title': 'Translated form',
'ra.configurable.inspector.hideAll': 'Translated hide all',
'ra.configurable.inspector.showAll': 'Translated show all',
};
const i18nProvider: I18nProvider = {
translate: (key, options) => messages[key] ?? options?._ ?? key,
changeLocale: () => Promise.resolve(),
getLocale: () => 'en',
};
render(
<I18nContextProvider value={i18nProvider}>
<Basic />
</I18nContextProvider>
);
screen.getByLabelText('Configure mode').click();
await screen.findByText('Inspector');
fireEvent.mouseOver(
screen.getAllByDisplayValue('War and Peace')[0]
);
await screen.getByTitle('ra.configurable.customize').click();
await screen.findByText('Translated form');
expect(screen.queryByText('Translated hide all')).not.toBeNull();
expect(screen.queryByText('Translated show all')).not.toBeNull();
});
});

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.

Can you reuse stories in SimpleFormConfigurable.stories.tsx:97. You just have to add fr language to that story to be able to create a realistic test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4034bc2: the I18N story now has French and a locale prop, and the test renders <I18N locale="fr" /> and checks the French inspector title and Hide all / Show all buttons.

Add French to the SimpleFormConfigurable I18N story (with a locale
prop) and test the inspector against it, as suggested in review.

This branch had an error being deployed

1 failed deployment
Preview – react-admin-storybook — 4034bc21 Deployed Nov 25, 2026 by vercel[bot]
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