Repository navigation
fix: set i18next default namespace so the desktop app can render - #159
Merged
Merged
Conversation
i18next was initialised without ns/defaultNS, so besides the namespaces each component asks for it also requested its built-in default, translation, which has no file under public/locales. On the web the miss is a 404 and i18next gives up after one warning. In the packaged Electron app, electron-serve's app:// protocol reports the missing file as a network failure, so i18next-http-backend keeps retrying, the namespace never settles, and react-i18next's Suspense never resolves: the window stays blank. Point the default namespace at common, which exists for both locales. Every useTranslation / i18n.t call already passes an explicit namespace, so no lookup changes.
wendyyuchensun
approved these changes
Oct 3, 2026
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
打包後的桌面版(Electron)啟動後視窗一片空白。原因是 i18next 初始化時沒有設定
ns/defaultNS,除了各元件指定的 namespace 之外,還會去載入內建預設的translation,而public/locales/*/translation.json從未存在。app://協定把缺檔回報成網路錯誤(ERR_FILE_NOT_FOUND),i18next-http-backend 視為可重試而不斷重試,namespace 永遠載不完,react-i18next 的 Suspense 不會 resolve,#root一直是空的。Changes
src/lib/i18n.js:init加上ns: ['common']與defaultNS: 'common',把預設 namespace 指到兩個語系都有的common.json。所有
useTranslation(...)(12 處)與i18n.t(..., { ns })(2 處)都已明確指定 namespace,沒有任何呼叫依賴預設值,所以不會改變任何翻譯查找結果。Verification
以同一支 CDP 探針對打包後的 app(macOS arm64,全新 user data 目錄)輪詢 20 秒:
translation.json請求#root無子元素vite preview):zh-TW 與?locale=en的標題、按鈕、aria-label 皆正確翻譯,不再請求translation.json,console 無警告。npm run lint、npm run format:check、npm test(8/8)通過。npm run build、npx electron-forge package成功。Notes
i18n.js自 2024-01 起未變動,與 Vite 遷移無關;v2.1.1 的 Windows 安裝檔是同一份設定。Windows(Squirrel)安裝版未實機驗證,建議合併後發版時在 Windows 上確認一次。debug: true在正式版仍開啟,console 會輸出大量 i18next log,可另外改成只在開發模式啟用。