Skip to content

[RFR] Improve translation loading - #3152

Merged
fzaninotto merged 3 commits into
marmelab:masterfrom
nik-lampe:master
Apr 25, 2019
Merged

fzaninotto merged 3 commits into
marmelab:masterfrom
nik-lampe:master

Conversation

@nik-lampe

Copy link
Copy Markdown
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

djhi commented Apr 21, 2019

Copy link
Copy Markdown
Contributor

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

@nik-lampe

Copy link
Copy Markdown
Contributor Author

Oops, true, fixed it. Thanks 🙌

@djhi djhi left a comment

Copy link
Copy Markdown
Contributor

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


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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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