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] Improve translation loading #3152

Merged
merged 3 commits into from
Apr 25, 2019
Merged

Conversation

nik-lampe
Copy link
Contributor

These changes do two things:

  • When receiving a new locale and messages it's not only checked if the locale has changed but also if the messages have changed. This fixes Translations not updating using an async function as provider and not changing language key #3139 .
    Object comparison might not be the best use here, but I think that the messages object won't be too large for it to still be performant.

  • It will start showing the fetch spinner before loading the translations and end it afterwards. This is useful when translations are loaded async. When it takes longer, the user doesn't know that anything is happening and then suddenly the strings switch.
    This might be improved to delay it for a short while, so there is no spinner when the messages are returned immediately.

@djhi
Copy link
Collaborator

djhi commented Apr 21, 2019

Build is failing because you did not apply eslint on the modified files.

@nik-lampe
Copy link
Contributor Author

Oops, true, fixed it. Thanks 🙌

Copy link
Collaborator

@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.

This might be improved to delay it for a short while, so there is no spinner when the messages are returned immediately.

I tried it on the demo. It does not even appear. It does trigger a useless state update though. I don't think it matters

@@ -56,7 +56,7 @@ class TranslationProviderView extends Component<ViewProps, State> {
}

componentDidUpdate(prevProps) {
if (prevProps.locale !== this.props.locale) {
if (prevProps.locale !== this.props.locale || prevProps.messages !== this.props.messages) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're comparing object references here for messages. This should be enough as the reference to the messages object should change when loading new ones

@djhi djhi added this to the 2.9.0 milestone Apr 21, 2019
@fzaninotto fzaninotto merged commit 998bca1 into marmelab:master Apr 25, 2019
@fzaninotto
Copy link
Member

Thanks!

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.

Translations not updating using an async function as provider and not changing language key
3 participants