Skip to content

fix: language switch silently fails when namespace file missing#102

Merged
BitHighlander merged 2 commits into
developfrom
fix/i18n-language-switch
Apr 7, 2026
Merged

fix: language switch silently fails when namespace file missing#102
BitHighlander merged 2 commits into
developfrom
fix/i18n-language-switch

Conversation

@BitHighlander
Copy link
Copy Markdown
Collaborator

Summary

  • Clicking a language in Settings did nothing — UI stayed in English
  • Root cause: i18next declares 14 namespaces (common, nav, dashboard, send, receive, asset, settings, device, setup, update, appstore, dialogs, swap, staking), but every non-English locale is missing one of them:
    • 9 locales missing swap.json: es, de, fr, it, ja, ko, pt, ru, zh
    • 5 locales missing staking.json: nl, pl, th, tr, vi
  • On changeLanguage('es'), Vite's __variableDynamicImportRuntimeHelper throws for the missing file → resourcesToBackend callback rejects → changeLanguage() promise rejects → language never actually switches
  • Fix: .catch(() => ({ default: {} })) on the dynamic import so missing namespaces become empty resources; i18next falls back to English for just that one namespace (via fallbackLng) and the rest switches correctly

Follow-up work (not in this PR): add the missing swap.json / staking.json files per locale for full translations.

Test plan

  • make build and launch app
  • Open Settings → Language → click Español → verify UI updates to Spanish
  • Repeat for at least one locale missing swap (es, de, fr) and one missing staking (nl, pl)
  • Reload app → confirm language persisted

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.
@BitHighlander BitHighlander merged commit 4c4bea4 into develop Apr 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant