maboloshi/github-chinese · error · Error
[GitHub 中文化插件] 詞庫文件 locals.js 未加載
Error message
[GitHub 中文化插件] 詞庫文件 locals.js 未加載
What it means
The Traditional-Chinese variant of the same guard. Its vocabulary comes from a separate file locals_zh-TW.js (generated from locals.js by an opencc sync workflow) required via // @require .../locals_zh-TW.js?v1.9.4.4-2026-06-21. When that generated dictionary did not load, typeof I18N === 'undefined' and the script alerts in Traditional Chinese then throws.
Source
Thrown at main_zh-TW.user.js:143
// 當前運行時狀態
pageConfig: null, // 當前頁面配置(null 表示無有效頁面)
currentURL: window.location.href, // 當前頁面URL
transEngine: 'iflyrec', // 當前翻譯引擎
mutationObserver: null, // DOM變化觀察器
urlChangeHandler: null, // 存儲URL變化處理器
dynamicMenus: {}, // 動態菜單ID記錄
initDone: false,
};
/* =========================== 安全檢查 =========================== */
/**
* 檢查詞庫文件是否加載 — 未加載則拋出錯誤阻止繼續執行
*/
function checkI18NLoaded() {
if (typeof I18N === 'undefined') {
alert('GitHub 漢化插件:詞庫文件 locals.js 未加載,腳本無法運行!');
throw new Error('[GitHub 中文化插件] 詞庫文件 locals.js 未加載');
}
}
/**
* 錯誤邊界 — 包裝函數,捕獲異常避免阻斷頁面正常使用
* @param {Function} fn - 要執行的函數
* @param {string} label - 錯誤標簽
* @returns {Function} 包裝後的函數
*/
function safe(fn, label) {
return function (...args) {
try {
return fn.apply(this, args);
} catch (e) {
console.error(`[GitHub 中文化插件] ${label} 出錯:`, e);
}
};
}View on GitHub (pinned to 1db777260a)
Solutions
- Open the exact locals_zh-TW.js @require URL; a 404 means the zh-TW artifact is missing — fall back to the Simplified main.user.js build (whose locals.js is always published) until the sync workflow runs.
- Confirm the .github/workflows opencc sync step produced and committed locals_zh-TW.js, then update the @require version to match the published file.
- If the host is blocked, switch to the NJU mirror variant or a local file:/// @require with local-file access enabled.
- Re-fetch @require resources in the manager (reinstall / edit+save) after the file is published.
Example fix
// before // @require https://raw.githubusercontent.com/mabolashi/github-chinese/gh-pages/locals_zh-TW.js?v1.9.4.4-2026-06-21 // after — zh-TW artifact missing, temporarily require the Simplified dictionary // @require https://raw.githubusercontent.com/mabolashi/github-chinese/gh-pages/locals.js?v1.9.4.4
Defensive patterns
Strategy: validation
Validate before calling
// Before init(), confirm the zh-TW dictionary actually loaded:
if (typeof I18N === 'undefined' || !I18N || typeof I18N !== 'object') {
console.error('[github-chinese] locals_zh-TW.js not loaded — aborting');
return;
} Type guard
function isI18NPresent(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null;
} Try / catch
try {
checkI18NLoaded();
init();
} catch (e) {
console.warn('[github-chinese] skipped:', e instanceof Error ? e.message : e);
} Prevention
- Gate releases on the opencc sync producing locals_zh-TW.js (CI check the file exists).
- Verify the @require version/date matches a published zh-TW file.
- Keep a Simplified-locale fallback @require for when the zh-TW artifact lags.
- Ensure the manager fetches @require resources on install.
When it happens
Trigger: The @require of locals_zh-TW.js on gh-pages 404s — the zh-TW sync workflow (opencc -i locals.js -o locals_zh-TW.js) has not run or the file is missing on the published branch — so the global I18N is undefined at line 165. Also fires if raw.githubusercontent.com is unreachable or @require is disabled in the manager.
Common situations: A release where the zh-TW generation step was skipped or failed in CI, leaving locals_zh-TW.js absent at the pinned version; the @require version string pointing at a date (2026-06-21) that has no corresponding published file; network blocking of raw.githubusercontent.com; manager @require disabled.
Related errors
AI-assisted analysis of maboloshi/github-chinese@1db777260a (2026-08-13).
Data as JSON: /api/errors/798fad408d98c64c.
Report an issue: GitHub.