api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
481 stars 130 forks source link

Translations are not working on v3 #449

Closed 7system7 closed 2 years ago

7system7 commented 2 years ago

API Platform version(s) affected: 3.x

Description
I upgraded a project to React Admin v4. (And to api-platform/admin v3) I use the same i18nProvider file (than before) and the same attributes to use my custom translations.

admin.js

<HydraAdmin
            i18nProvider={i18nProvider} locale="en"

i18nProvider.js

import polyglotI18nProvider from 'ra-i18n-polyglot';
import englishMessages from '@yc/messages/en.messages';

const messages = {
    'en': englishMessages,
};

const i18nProvider = polyglotI18nProvider(
    locale => messages[locale],
    'en',
    {
        allowMissing: true
    }
);

export default i18nProvider;

en.messages.js

import englishMessages from 'ra-language-english';

export default {
    ...englishMessages,
    resources: {
        users: {
            name: 'User |||| Users',
            fields: {
                hello: 'Bello',

How to reproduce
Use the api-platform/admin v3 with React Admin v4 and create an i18nProvier. After you will see translations like this:

Screenshot from 2022-04-24 23-05-37

Possible Solution

  1. Use the React Admin only. If you use import { Admin } from "react-admin" instead of import { HydraAdmin } from "@api-platform/admin" then the translation works w/ the new version too. (It is not an option on a lot of project, I think.)
  2. Downgrade one major version. (To the react-admin v3 and the @api-platform/admin v2)

Additional Context

alanpoulain commented 2 years ago

Hello, The 3.1.0 version should solve your issue, tell me if it's not the case.

7system7 commented 2 years ago

It works. This was quick. Thank you!