The plugin never translated anything. Its client half monkey-patched locale internals that do not mutate the locale snapshot, and its DOM walker was disabled after it crashed the marketplace UI. Nothing else was left. Move translation to the bundle transport instead. Every third-party bundle is served through /plugins/ by the clientModules service, so wrapping bundleResource reaches all of them before any code runs, with no client-side ordering race and no React tree mutation. Two bugs surfaced while verifying against the live server: - The script check tested the path before the query string, but combo requests are /plugins/??a/client.js,b/client.js&rev=... where the path is just /plugins/. Every request was rejected. - bundleResource yields a Buffer, not a string, so the string guard rejected every request a second time. Rewriting is all-or-nothing per literal: Chinese has no word boundaries, so replacing known keys wherever they appear corrupts larger words (当前工作区 became "Saat IniWorkspace"). A literal is translated only when every Chinese character is covered by a dictionary entry. Two upstream entries were Malay rather than English and are now corrected. Each rewritten bundle is parsed with new Function before being served; if that fails the original bytes are returned, so a bad dictionary entry cannot break the UI. Verified against the live bundles: both combos compile, and a browser A/B shows 105 Chinese characters in the Plugins view without the plugin and 0 with it. The dictionary grows to 1,195 entries (45% of literals, zero partial rewrites) via a curated supplement merged last so it overrides harvested sources.
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
window.__ModuleLoader__.load({ id: "chinese2english", factory: (require) => { var module = { exports: {} }; var exports = module.exports;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name2 in all)
|
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/client/index.ts
|
|
var index_exports = {};
|
|
__export(index_exports, {
|
|
apply: () => apply,
|
|
inject: () => inject,
|
|
name: () => name
|
|
});
|
|
module.exports = __toCommonJS(index_exports);
|
|
var name = "chinese2english";
|
|
var inject = ["locale"];
|
|
function apply(ctx) {
|
|
const locale = ctx.locale;
|
|
if (!locale || typeof locale.setLocale !== "function") {
|
|
console.warn("[chinese2english] locale service unavailable; UI language left unchanged");
|
|
return;
|
|
}
|
|
const pin = (reason) => {
|
|
try {
|
|
if (locale.getLocale?.().active === "en") return;
|
|
locale.setLocale("en");
|
|
} catch (error) {
|
|
console.error(`[chinese2english] could not select English (${reason}):`, error);
|
|
}
|
|
};
|
|
pin("initial");
|
|
ctx.effect(
|
|
() => ctx.on("locale/change", (snapshot) => {
|
|
if (snapshot?.active !== "en") pin("locale change");
|
|
}),
|
|
"chinese2english: keep the UI locale on English"
|
|
);
|
|
}
|
|
return module.exports; } });
|
|
//# sourceMappingURL=client.js.map
|