i18n: client-editable German dictionary + limit UI languages to de/en

Two client requests on the v4.5.2 German build:

1. Editable/persistent translations. German dictionaries now live at
   branding/i18n/locales/{de,en}.json (the client edits these). apply-branding.mjs
   overlays them onto web/public/locales/<lang>/common.json AFTER the patch, so edits
   survive make setup (previously the dict was inside the patch and got overwritten).
   Added MISSING-de.md (the ~12 non-admin keys still English; dict is ~98% complete).

2. Limit the selector to German + English. New config i18n.languages=["de","en"];
   apply strips every other bundled language (es/fr/pt) from i18n.ts (imports +
   resources), the Settings selector, and public/locales. Config-driven + idempotent.

Note for coverage: dictionary edits only reach strings that are t()-wrapped. Components
kept at v4.5.2 during the re-sync (never-break-UI) render English regardless — those need
a component-wrapping pass (separate dev work), documented in README.

Verified in a built image: compiles (4.8min); de+en dictionaries served (200),
es/fr/pt removed (404); homepage 200.
This commit is contained in:
NaeemDosh 2026-08-11 05:44:59 +05:00
parent 01b9adfcd9
commit ea2c56f9e0
6 changed files with 4333 additions and 6 deletions

View file

@ -183,10 +183,27 @@ It's wired into the overlay, config-driven from `branding.config.json → i18n`:
### Editing the German translations ### Editing the German translations
Fill in / refine `web/public/locales/de/common.json` (the PR already ships a full German Edit **`branding/i18n/locales/de.json`** — the client-editable source dictionary (JSON,
draft). Keys are grouped by area (`chat`, `sidebar`, `auth`, `onboarding`, …). Then keys grouped by area: `chat`, `sidebar`, `auth`, `onboarding`, …). `make apply` copies it
`make apply && make build && make restart`. Add another language by dropping in a new over the bundled dictionary, so **your edits persist across `make setup`** (don't edit
`web/public/locales/<lang>/common.json`. `web/public/locales/**` directly — the overlay regenerates it). Then
`make apply && make build && make restart`.
`branding/i18n/MISSING-de.md` lists the dictionary keys that are still English (currently
~12 non-admin keys — the German draft is ~98% complete).
> **Two kinds of "missing":** editing the dictionary fixes keys that are *wired for
> translation* but lack a German value. Text in the components that were kept at v4.5.2
> during the re-sync (the never-break-UI ones) is **not wired** — it shows English no
> matter what the dictionary says, and only a component-wrapping pass (dev work) adds it.
> So dictionary edits refine coverage; they don't reach the un-wrapped components.
### Which languages appear
The UI language selector is limited to **`i18n.languages`** in `branding.config.json`
(currently `["de", "en"]`). `make apply` strips every other bundled language (es/fr/pt)
from `i18n.ts` and the Settings selector. To offer another language: add its code to that
list **and** a dictionary at `branding/i18n/locales/<code>.json`.
### Retiring it (when official i18n ships) ### Retiring it (when official i18n ships)

View file

@ -13,7 +13,7 @@
// fallbacks, hardcoded strings, logo components and favicon). It does NOT enable // fallbacks, hardcoded strings, logo components and favicon). It does NOT enable
// or depend on Onyx's Enterprise white-label feature (enterprise-settings). // or depend on Onyx's Enterprise white-label feature (enterprise-settings).
// ───────────────────────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────────────────────
import { readFile, writeFile, copyFile, mkdir, readdir, stat } from "node:fs/promises"; import { readFile, writeFile, copyFile, mkdir, readdir, stat, rm } from "node:fs/promises";
import { existsSync } from "node:fs"; import { existsSync } from "node:fs";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { execFileSync } from "node:child_process"; import { execFileSync } from "node:child_process";
@ -79,6 +79,48 @@ if (CONFIG.i18n && CONFIG.i18n.enabled) {
if (DRY) ok("i18n patch applies cleanly (dry-run, not written)"); if (DRY) ok("i18n patch applies cleanly (dry-run, not written)");
else { gitApply([]); ok(`applied i18n patch — react-i18next, user UI only (Admin stays English); default language ${CONFIG.i18n.defaultLanguage}`); } else { gitApply([]); ok(`applied i18n patch — react-i18next, user UI only (Admin stays English); default language ${CONFIG.i18n.defaultLanguage}`); }
} }
// Restrict the offered languages to CONFIG.i18n.languages and overlay the
// client-editable dictionaries so translation edits persist across `make setup`.
// Idempotent — safe whether the patch was just applied or already present.
if (!DRY && existsSync(sentinel)) {
const ALL = ["en", "es", "pt", "fr", "de"];
const keep = CONFIG.i18n.languages?.length ? CONFIG.i18n.languages : ALL;
const drop = ALL.filter((l) => !keep.includes(l));
const i18nTs = path.join(WEB, "src/lib/i18n.ts");
let ts = await readFile(i18nTs, "utf8");
for (const l of drop) {
ts = ts.replace(new RegExp(`^\\s*import \\w+ from "\\.\\./\\.\\./public/locales/${l}/common\\.json";\\n`, "m"), "");
ts = ts.replace(new RegExp(`^\\s*${l}: \\{ common: \\w+ \\},\\n`, "m"), "");
}
await writeFile(i18nTs, ts);
const settings = path.join(WEB, "src/views/SettingsPage.tsx");
let sp = await readFile(settings, "utf8");
for (const l of drop) {
sp = sp.replace(new RegExp(`^\\s*<InputSelect\\.Item value="${l}">[^<]*</InputSelect\\.Item>\\n`, "m"), "");
}
await writeFile(settings, sp);
for (const l of drop) {
const d = path.join(PUBLIC, "locales", l);
if (existsSync(d)) await rm(d, { recursive: true, force: true });
}
let overlaid = 0;
const dictDir = CONFIG.i18n.dictionaries ? path.join(ROOT, CONFIG.i18n.dictionaries) : null;
if (dictDir) for (const l of keep) {
const srcDict = path.join(dictDir, `${l}.json`);
const destDict = path.join(PUBLIC, "locales", l, "common.json");
if (existsSync(srcDict)) {
await mkdir(path.dirname(destDict), { recursive: true });
await copyFile(srcDict, destDict);
overlaid++;
}
}
ok(`languages: ${keep.join("/")} (dropped ${drop.length ? drop.join("/") : "none"}); overlaid ${overlaid} client dictionar${overlaid === 1 ? "y" : "ies"}`);
}
} }
} }

View file

@ -21,7 +21,11 @@
"patch": "branding/i18n/end-user-i18n.patch", "patch": "branding/i18n/end-user-i18n.patch",
"baseCommit": "v4.5.2", "baseCommit": "v4.5.2",
"defaultLanguage": "de", "defaultLanguage": "de",
"rebrandLocales": true "rebrandLocales": true,
"languages": ["de", "en"],
"$languages_comment": "Languages offered in the UI selector. Any of the PR's bundled languages NOT listed here (es/fr/pt) are stripped from i18n.ts + the Settings selector at apply time. To offer another language, add its code here AND a dictionary at dictionaries/<code>.json.",
"dictionaries": "branding/i18n/locales",
"$dictionaries_comment": "Client-editable source dictionaries. After the patch is applied, apply-branding.mjs copies dictionaries/<lang>.json over web/public/locales/<lang>/common.json — so edits here PERSIST across `make setup` (they're the source of truth, not the patch). Edit branding/i18n/locales/de.json to add/refine German (see MISSING-de.md for untranslated keys), then `make apply && make build`."
}, },
"build": { "build": {

View file

@ -0,0 +1,16 @@
# Untranslated German keys (still showing English)
Edit these in `branding/i18n/locales/de.json`, then `make apply && make build`.
- `general.chat` = "Chat"
- `chat.tool_display.tool` = "Tool"
- `settings.theme.logo_and_name` = "Logo & Name"
- `settings.appearance.mode_auto` = "Auto"
- `settings.chats.title` = "Chats"
- `settings.chats.mode_chat` = "Chat"
- `settings.token_rate_limits.tab_global` = "Global"
- `settings.usage.feedback_title` = "Feedback"
- `onboarding.theme.logo_and_name` = "Logo & Name"
- `onboarding.token_rate_limits.tab_global` = "Global"
- `onboarding.usage.feedback_title` = "Feedback"
- `agents.agent_singular` = "Agent"

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff