Files
Claude 77a7098051 i18n core: the Mac's strings, a key-based t() for the webviews and Rust
Strings are looked up by their English text, like the Mac's catalog:
t("Allow"), t("Uploading {name}", { name }), tn(one, other, n) for plurals.

- scripts/gen-strings.mjs turns NotchBuddy/Resources/Localizable.xcstrings
  into src/i18n/strings.json: Mac keys such as "step.reads" become their
  English text, %@ / %lld become {placeholders} (named where the Windows
  code uses them), plural variations keep their categories.
- src/i18n/extra.json holds the strings only Windows and Linux show, in
  all ten languages.
- src/i18n/i18n.ts: lookup with English fallback, Intl plural rules, the
  System choice (system language when Coucou has it, else English; pt → pt-BR,
  zh-CN → zh-Hans), dates through Intl, and onLanguageChange.
- views/dom.ts: a tl(…) text given to h() relabels itself in place when the
  language changes, so no view has to be rebuilt.
- src-tauri/src/i18n.rs embeds the same two files with include_str! and
  answers the same way (t, tf, tn); its tests run in English per thread.
- Tests load the JSON through the setup hook, as Vite does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DMzyoPKtGVNBUemdZhnWRG
2026-10-08 00:00:29 +02:00

33 lines
1.3 KiB
JavaScript

// Loaded before every test file (see the `test` script in package.json).
// Node runs the island's TypeScript as it is; this only supplies what the
// webview and the bundler normally would.
import { readFileSync } from "node:fs";
import { registerHooks } from "node:module";
import { fileURLToPath } from "node:url";
import { internals } from "./tauri.mjs";
// The sources import each other without an extension, which Vite resolves.
registerHooks({
resolve(specifier, context, nextResolve) {
const ours = !context.parentURL?.includes("/node_modules/");
if (ours && specifier.startsWith(".") && !/\.(?:[cm]?[jt]s|json)$/.test(specifier)) {
return nextResolve(`${specifier}.ts`, context);
}
return nextResolve(specifier, context);
},
// Vite imports JSON (src/i18n/*.json) without `with { type: "json" }`;
// Node would refuse it, so it is handed over as a module.
load(url, context, nextLoad) {
if (url.startsWith("file:") && url.endsWith(".json") && !url.includes("/node_modules/")) {
const source = readFileSync(fileURLToPath(url), "utf8");
return { format: "module", source: `export default ${source};`, shortCircuit: true };
}
return nextLoad(url, context);
},
});
// The island reaches timers and Tauri through `window`.
globalThis.window = globalThis;
globalThis.__TAURI_INTERNALS__ = internals;