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

fix: forcibly take control of i18n singleton language #188

Closed
wants to merge 1 commit into from

Conversation

amcgee
Copy link
Member

@amcgee amcgee commented Nov 25, 2019

There's yet another race condition in our handling of i18n - in this case, any component that uses d2-i18n-generate will inject a i18n.setLanguage('en') which is loaded whenever that component is required (with dynamic imports this can be after initial page load!)

This "works around" this issue by always listening for i18n's languageChanged event and immediately resetting the language if it was "hijacked" out from under us - for instance if some component (cough Headerbar) ALSO has logic to set the locale when the user is logged in (which doesn't even work, different issue...) or worse tries to set it to something incorrect (like English)

There's still an issue here, since once the language is set (i.e. english on load in the headerbar) the strings won't be updated until that component re-renders - we may need to force a full-page rerender whenever the language changes, at least until we can make i18n react-aware, but that's an issue for another day.

Now the Login dialog in platform apps should always correctly adopt the browser locale, and the app should be correctly translated to the logged-in user's locale, but the headerbar will still appear in English.

@amcgee amcgee requested review from edoardo and varl November 25, 2019 23:17
@netlify
Copy link

netlify bot commented Nov 25, 2019

Deploy preview for dhis2-app-platform canceled.

Built with commit eb1265d

https://app.netlify.com/sites/dhis2-app-platform/deploys/5ddc610401f113000960ad8c

Copy link
Contributor

@varl varl left a comment

Choose a reason for hiding this comment

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

Not ideal, we need to figure out a way to "solve" i18n for our use case.

@stale
Copy link

stale bot commented May 26, 2020

Hi! Due to a lack of activity on this issue over time it seems to be stale. If still relevant, please provide information that moves it forward: e.g. more information, reason to keep it open, supply a pull request, etc.
Any activity will keep it open, otherwise it will be closed automatically. Thanks! 🤖

@stale stale bot added the stale label May 26, 2020
@stale
Copy link

stale bot commented Jun 25, 2020

Automatically closing due to lack of activity. 🤖

@stale stale bot closed this Jun 25, 2020
@varl varl deleted the fix/i18n-race-condition branch September 8, 2021 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants