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

Translations not updating using an async function as provider and not changing language key #3139

Closed
nik-lampe opened this issue Apr 18, 2019 · 3 comments · Fixed by #3152
Closed

Comments

@nik-lampe
Copy link
Contributor

nik-lampe commented Apr 18, 2019

What you were expecting:
When loading the translations from an async function (e.g. XHR Request) the translated keys should update.

What happened instead:
It only changes, when the action dispatched by the side effect has a different language key than the current selected language. If it's the same, then the TranslatedProvider does not rerender, because it's componentDidUpdate method only checks on the language key.

So even when you change to the same language again it won't update, if you haven't changed it to another language before.

Steps to reproduce:
It's a rare case, so I created a code sandbox.
https://yjvyo9yp29.codesandbox.io/#/posts/13

Only changed the i18nProvider and added a language switcher to an aside of the post edit view, where the resource keys are visible.

Other information:
I think this can be easily fixed by checking if the messages object changes in the TranslationProvider componentDidUpdate method.
But then still there are technical keys visible until the async function returns the translation. This could be solved by not rendering before translation is ready. But that's not very practical either.

Environment
react-admin 2.8.5

@djhi
Copy link
Collaborator

djhi commented Apr 21, 2019

I'm curious, why would you reload the same locale with different messages?

@nik-lampe
Copy link
Contributor Author

I think it's a rare case.
In my case it's because I save the translations in a database and have them editable by the user. And when changes are made and I just want to see the result I need to switch to another language and then back to the one I'm editing.

@djhi
Copy link
Collaborator

djhi commented Apr 21, 2019

Looks like a perfectly valid use case to me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants