fix: forcibly take control of i18n singleton language #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's yet another race condition in our handling of i18n - in this case, any component that uses
d2-i18n-generate
will inject ai18n.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.