-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Conversation
907bd21
to
9a64f32
Compare
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
TranslationProvider
using hooksuseSetLocale()
anduseLocale()
hooksuseLoading()
anduseUpdateLoading()
hooks (wrapper around the dispatching of loading actions)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.