Skip to content
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

Form validation errors are translated twice #8662

Closed
owenbendavies opened this issue Feb 16, 2023 · 2 comments · Fixed by #8700
Closed

Form validation errors are translated twice #8662

owenbendavies opened this issue Feb 16, 2023 · 2 comments · Fixed by #8700
Labels

Comments

@owenbendavies
Copy link

What you were expecting:
In our i18nProvider we have code to raise an error if a translation is missing

export const i18nProvider = {
  ...polyglotProvider,
  translate: (key: string, options: any) => {
    const translation = polyglotProvider.translate(key, options);

    if (translation === key) throw new Error(`missing translation "${key}"`);

    return translation;
  },
};

We are expecting validation translations to work when we have code to ensure translations aren't missing

<TextInput validate={minLength(10), 'error.minLength'} />

What happened instead:
It fails with Error: missing translation "Must be 10 characters at least"

Steps to reproduce:

  1. Add the above code
  2. Enter text in text input which is less than 10 characters

Other information:
If adding logging to the above function it does first get called with error.minLength then gets called with return value of that e.g. Must be 10 characters at least. I suspect somewhere it calling translate again when it is not needed.

I have found one area where this happens

label={translate('ra.navigation.skip_nav')}

But cannot find where this happen in the validation code.

Environment

  • React-admin version: 4.8.0
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17.0.2
  • Browser: any
  • Stack trace (in case of a JS error):
@slax57 slax57 added the bug label Feb 16, 2023
@slax57
Copy link
Contributor

slax57 commented Feb 16, 2023

Reproduced, thanks!
Stackblitz: https://stackblitz.com/edit/github-pwhz5l?file=src/posts/PostCreate.tsx

@owenbendavies
Copy link
Author

Great thank you @slax57, much easier than https://xkcd.com/583/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants