MPDX-9947 - Enforce useTranslation and disable use of i18n singleton - #1988
Open
zweatshirt wants to merge 2 commits into
Open
MPDX-9947 - Enforce useTranslation and disable use of i18n singleton#1988zweatshirt wants to merge 2 commits into
zweatshirt wants to merge 2 commits into
Conversation
Contributor
Bundle sizes [mpdx-react]Compared against 5f0edc3 No significant changes found |
Contributor
|
Preview branch generated at https://enforce-usetranslation.d3dytjb8adxkk5.amplifyapp.com |
zweatshirt
marked this pull request as ready for review
August 14, 2026 20:01
Contributor
Author
|
@dr-bizz Thanks for considering this. The core code is a lot less than the change implies. I listed the files that are important to look at. I did an agent review locally, it is mostly happy with the results, but this deserves a human look. Thanks Daniel! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Jira ticket: https://jira.cru.org/browse/MPDX-9947
Issue:
i18n.t() at module scope evaluates to a string at import time, before React renders and before translations have loaded. Since module bodies don't re-execute, those strings are frozen in English for the life of the page.
Two things in our setup make this unavoidable:
src/lib/i18n.tsusesi18next-http-backend, sotranslation.jsonis fetched over the network..init()is called synchronously but not awaited.UserPreferenceProvidercallsi18n.changeLanguage()in auseEffect, after theGetUserquery resolvesFix: Why
useTranslationinstead ofi18n.tuseTranslation()does two things, and the fix needs both:tis called inside the component body, so the expression re-evaluates on every render instead of once.languageChanged(react-i18next'sbindI18ndefault) andcalls
setTwith a fresh function, which guarantees that re-render actually happens whenUserPreferenceProviderapplies the saved language.Important files to review in this PR
Testing
Go to Settings → Preferences → Language → Deutsch, save, then open /accountLists/id/tools.
- On old code the tool names and descriptions stay English while the surrounding page chrome translates.
- In the preview environment with new code, the tool names and descriptions will change to the correct language.
Checklist:
/quality:agent-reviewcommand locally and fixed any relevant suggestions