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

[RFR] Refactor I18n layer to use hooks #3672

Merged
merged 10 commits into from
Sep 11, 2019
Merged

[RFR] Refactor I18n layer to use hooks #3672

merged 10 commits into from
Sep 11, 2019

Conversation

fzaninotto
Copy link
Member

  • [BC Break] Rewrite the TranslationProvider using hooks
  • [BC Break] Remove i18n reducer and saga
  • Add useSetLocale() and useLocale() hooks
  • Add useLoading() and useUpdateLoading() hooks (wrapper around the dispatching of loading actions)
  • Display a notification if locale change fails
  • Update documentation
  • Add upgrade guide

withTranslate is unchanged, and the i18nProvider signature stays the same. The only changes for existing apps are for getting and setting locale, and for custom apps).

But the code is now much easier to follow, and more idiomatic to modern React.

Added benefit: when using a custom app, developers can replace the TranslationProvider by their own and use another translate function than Polyglot (as long as it has the same signature) (refs #2307.

@fzaninotto fzaninotto added this to the 3.0.0 milestone Sep 11, 2019
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

🔥 💪

})
.catch(error => {
stopLoading();
notify('ra.notification.i18n_error', 'warning');
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a technical error. I'm not sure we should notify the end user about it

Copy link
Member Author

Choose a reason for hiding this comment

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

The error occurs while loading (potentially via http) a new set of messages. The problem may be on the user side (networking problem), at this stage there is no way to know.

I think it's preferable to show an error notification when the language switch fails, otherwise a user who pressed a 'change locale' button may hit the button again and again, thinking their click didn't work.

@djhi djhi merged commit f46bd66 into next Sep 11, 2019
@djhi djhi deleted the i18n-hook branch September 11, 2019 14:17
@fzaninotto fzaninotto mentioned this pull request Sep 13, 2019
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants