chore(cleanup): replace hand-rolled i18n loader with i18next - #199
Merged
EtienneLescot merged 3 commits intoJul 29, 2026
Conversation
Drops the 126-line bespoke loader in src/i18n/loader.ts for a ~70-line
wrapper around i18next. Locale-fallback, {{var}} interpolation, defaultNS,
and fallbackLng come from the library; we keep the same four exports
(getAvailableLocales, getLocaleName, getLocaleShort, translate) so
LaunchWindow, EditorTopBar, and I18nContext don't change.
Public API preserved: I18nContext still calls translate(locale, ns, key, vars);
the new translate is a thin shim around i18next.t. Miss behavior matches the
old loader (\{namespace}.{key}\ on miss, locale code on locale-name miss).
Test results:
- tsc --noEmit: clean
- vitest (i18n + LaunchWindow + components): all pass
- biome check: clean
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…marker fallback
The stored value fed only init({lng}), but every lookup passes an explicit lng,
so it never affected output — while adding a SecurityError path at module scope,
where it takes down the whole module graph instead of one component. I18nContext
already owns the preference behind a try/catch.
returnedObjectHandler restores the old loader's behaviour for a non-leaf key:
fall through to the 'namespace.key' marker rather than rendering i18next's
English developer message into the UI.
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
Replaces the 126-line hand-rolled i18n loader in
src/i18n/loader.tswith a ~70-line wrapper around the maintainedi18nextlibrary.{{var}}interpolation,defaultNS,fallbackLng, and locale resource loading all come from the library; the public API (getAvailableLocales,getLocaleName,getLocaleShort,translate) and the existing call sites inI18nContext,LaunchWindow, andEditorTopBarare unchanged.Heads-up: new runtime dependency
This PR adds
i18next@^23.16.0as a runtime dependency (it's the only new dep). The original audit marked this swap as "needs a maintainer's blessing" since it pulls a maintained library into the bundle. 23.x is the conservative pick (same major that was current when the audit was written); 26.x is the current stable and would also work for our minimalinit+tsurface.Bundle cost: ~12 kB minified for i18next core (no plugins, no
react-i18next, no backend — we feed the resources inline viaimport.meta.glob).Maintainer eyeball pass
The library is wired to all 13 locales × 7 namespaces = 91 JSON files. The
exists()+t()shim falls back to theentranslation for missing keys at runtime (i18next handles this viafallbackLng: 'en'), and the existingsrc/i18n/__tests__/localeParity.test.tsalready enforces that every locale has everyenkey at build time. A quick eyeball pass against the 91 files would be appreciated before merge.Notes on interpolation behavior
The new loader uses i18next's default
{{var}}regex, which matches the hand-rolled loader's/\{\{(\w+)\}\}/gexactly. The only intentional divergence: i18next is configured withinterpolation: { escapeValue: false }because React escapes at the render boundary; the old loader had no escaping at all. This only matters if a translation value contains<or>— and since all of our vars arestring | number(file names, project names, counts), the user-visible output is identical.Test results
npx tsc --noEmit: cleannpx vitest --run src/i18n src/components/launch/LaunchWindow.test.tsx: 40/40 passnpx vitest --run src/: 904/904 pass; the only file-level failures are a pre-existingpixi.jsresolution issue in this worktree's fresh install (unrelated to this change — same tests pass in the main checkout)npx biome check src/i18n/loader.ts package.json: cleanDiff summary
The
package-lock.jsondiff is mostly stale-entry cleanup (28 packages like@langchain/langgraph,gsap,uuid,langsmith,emoji-picker-react,@pixi/filter-drop-shadowwere no longer inpackage.jsonbut still in the lock). One new entry:node_modules/i18next.Type of change
Release impact
Desktop impact
Testing
All clean. Full
npm run testshows 904/904 pass; the few file-level failures are pre-existingpixi.jsresolver issues in this worktree's freshnode_modulesand are reproducible on the base branch with the worktree'snode_modulesstate.