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

feature: Added the ability to localize RJSF internal strings #3460

Merged
merged 8 commits into from
Mar 2, 2023

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Feb 27, 2023

Reasons for making this change

True fix for #205 to support localizing the internal strings in @rjsf

  • In @rjsf/utils, added TranslatableString enum and englishStringTranslator() and replaceStringParameters() to support localization
    • Also updated the Registry type to add the translateString function
    • Added 100% unit testing for the new functions
  • In @rjsf/core, added a new translateString prop to FormProps as well as using that prop in the registry if provided
    • Updated the getDefaultRegistry() to set translateString to englishStringTranslator
    • Updated ArrayField, BooleanField, MultiSchemaField, ObjectField, SchemaField, AddButton, IconButtons, ErrorList, WrapIfAdditionalTemplate and AltDateWidget and FileWidget to use translateString
    • Added the markdown-to-jsx to support localizing the UnsupportedField
  • In all the themes, updated ErrorList, IconButtons, AddButton, WrapIfAdditionalTemplate and where applicable AltDateWidget to use translateString from the registry
    • Updated the snapshots for UnsupportedField based on the cleaned up translation formatting
  • In @rjsf/semantic-ui, updated the FieldErrorTemplate and FieldHelpTemplate to use the errorId() and helpId() functions
  • Updated the utility-functions docs for the enums and the new functions
  • Updated the form-props docs to describe the new translateString prop
  • Updated the CHANGELOG accordingly

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

True fix for rjsf-team#205 to support localizing the internal strings in @rjsf
- In `@rjsf/utils`, added `TranslatableString` enum and `englishStringTranslator()` and `replaceStringParameters()` to support localization
  - Also updated the `Registry` type to add the `translateString` function
  - Added 100% unit testing for the new functions
- In `@rjsf/core`, added a new `translateString` prop to `FormProps` as well as using that prop in the `registry` if provided
  - Updated the `getDefaultRegistry()` to set `translateString` to `englishStringTranslator`
  - Updated `ArrayField`, `BooleanField`, `MultiSchemaField`, `ObjectField`, `SchemaField`, `AddButton`, `IconButton`s, `ErrorList`, `WrapIfAdditionalTemplate` and `AltDateWidget` and `FileWidget` to use `translateString`
  - Added the `markdown-to-jsx` to support localizing the `UnsupportedField`
- In all the themes, updated `ErrorList`, `IconButton`s, `AddButton`, `WrapIfAdditionalTemplate` and where applicable `AltDateWidget` to use `translateString` from the registry
  - Updated the snapshots for `UnsupportedField` based on the cleaned up translation formatting
- In `@rjsf/chakra-ui`, updated `TextAreaWidget` and `UpDownWidget` to switch `??` syntax to `||`
- In `@rjsf/semantic-ui`, updated the `FieldErrorTemplate` and `FieldHelpTemplate` to use the `errorId()` and `helpId()` functions
- Updated the `utility-functions` docs for the enums and the new functions
- Updated the `form-props` docs to describe the new `translateString` prop
- Updated the `CHANGELOG` accordingly
Copy link
Contributor

@nickgros nickgros left a comment

Choose a reason for hiding this comment

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

Looks great! Couple of notes--not sure if they are real issues. See comments before merging.

Documented support for markdown and html as well
More documentation updates
@heath-freenome heath-freenome merged commit 744e87c into rjsf-team:main Mar 2, 2023
@heath-freenome heath-freenome deleted the add-i18n-support branch March 2, 2023 08:05
@zlldnv
Copy link

zlldnv commented Aug 2, 2023

Hey @heath-freenome thank you very much for adding this improvement into library!
Would more examples how to use this improvement arrive? Even here or in the docs?
Is ‘t’ from i18next a good candidate for the translationString prop? If yes how to use it with json schema?
Thanx!

@heath-freenome
Copy link
Member Author

@zlldnv Have you looked at the examples in the docs? All of the translatable strings can be found here. I'm not familiar with t.

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.

3 participants