fix: language switch silently fails when namespace file missing#102
Merged
Conversation
i18next is configured with 14 namespaces (incl. swap, staking), but
non-English locales are each missing one of them — 9 locales lack
swap.json, 5 lack staking.json. On changeLanguage('es'), Vite's dynamic
import helper throws for the missing file, rejecting the
resourcesToBackend callback, which aborts the whole language switch.
UI silently stays in English.
Catch the import rejection and return an empty resource. i18next then
falls back to English for just that namespace (via fallbackLng) and
successfully switches language for everything else.
Previous fix swallowed every dynamic-import failure, which would hide real regressions (chunk load failures, malformed JSON, bad paths) as silent English fallbacks — much harder to detect in production. Match only Vite's specific "Unknown variable dynamic import" error (thrown when the path isn't in the generated import map, i.e. the translation file genuinely doesn't exist), warn once, and return an empty namespace. Rethrow everything else so real failures surface.
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.
Summary
common,nav,dashboard,send,receive,asset,settings,device,setup,update,appstore,dialogs,swap,staking), but every non-English locale is missing one of them:swap.json: es, de, fr, it, ja, ko, pt, ru, zhstaking.json: nl, pl, th, tr, vichangeLanguage('es'), Vite's__variableDynamicImportRuntimeHelperthrows for the missing file →resourcesToBackendcallback rejects →changeLanguage()promise rejects → language never actually switches.catch(() => ({ default: {} }))on the dynamic import so missing namespaces become empty resources; i18next falls back to English for just that one namespace (viafallbackLng) and the rest switches correctlyFollow-up work (not in this PR): add the missing
swap.json/staking.jsonfiles per locale for full translations.Test plan
make buildand launch appswap(es, de, fr) and one missingstaking(nl, pl)