[PR #4100] [MERGED] Add Documentation Language selector with downloadable language pack (first pack: Spanish) #6234

Closed
opened 2026-10-23 04:08:26 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4100
Author: @kolacheee
Created: 7/25/2026
Status: ✅ Merged
Merged: 7/25/2026
Merged by: @SpicyMarinara

Base: staging ← Head: agent/docs-language-es


📝 Commits (9)

  • 4023dfd Add Documentation Language selector with per-file English fallback
  • a2a3ce5 Add Spanish (es) translations for all user-facing docs
  • 6597c02 Rework Documentation Language to download-on-demand packs
  • 12195c8 Harden docs pack switching from second review round
  • 04bb884 Auto-refresh the selected docs pack after Engine updates
  • 039186f Render indented code fences correctly in shared markdown
  • 3717caa Add Documentation Language feature to the changelog
  • 5a8a400 Merge remote-tracking branch 'origin/staging' into agent/docs-language-es
  • 5d3e93c Reference #4100 in the changelog entries

📊 Changes

22 files changed (+1782 additions, -48 deletions)

View changed files

📝 .github/pull_request_template.md (+1 -0)
📝 AGENTS.md (+1 -0)
📝 CHANGELOG.md (+3 -0)
📝 CLAUDE.md (+1 -0)
📝 CONTRIBUTING.md (+8 -0)
📝 docs/CONFIGURATION.md (+1 -0)
📝 docs/UPGRADING.md (+2 -0)
📝 package.json (+2 -1)
📝 packages/client/src/components/modals/DocsViewerModal.tsx (+63 -12)
📝 packages/client/src/components/onboarding/OnboardingTutorial.tsx (+99 -4)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+156 -0)
➕ packages/client/src/hooks/use-docs-language.ts (+99 -0)
📝 packages/client/src/hooks/use-docs.ts (+40 -14)
📝 packages/client/src/lib/markdown.tsx (+11 -2)
📝 packages/client/src/localization/locales/en.json (+23 -0)
📝 packages/server/src/routes/docs.routes.ts (+370 -15)
➕ packages/server/src/services/docs/docs-pack.service.ts (+483 -0)
➕ packages/shared/src/constants/docs-languages.ts (+30 -0)
📝 packages/shared/src/index.ts (+1 -0)
➕ scripts/docs-i18n/build-manifest.mjs (+82 -0)

...and 2 more files

📄 Description

Why

International users currently get English-only in-app guides. This PR adds a Documentation Language setting (Settings › General, plus a final step in the onboarding tutorial) with download-on-demand language packs, and ships the first full translation: Spanish, covering all 123 guides (developer docs included, so non-English-speaking contributors can build PRs and extensions too).

Packs live on the companion docs-i18n orphan branch — never in user checkouts. Launchers only fetch main/staging and the installer clones a single tag, so translations add zero checkout/image size: important for Termux and thin-client installs as FIGS(P)/CJK land later (~1.3 MB per language ≈ 13 MB at ten languages, downloaded at most once by the users who want it).

How it works

  • Selector: Settings › General › Documentation Language (below the UI-language selector; findable via settings search) and a dedicated final onboarding step (pre-selects the UI language on fresh installs; on replays it pre-selects the user's existing choice, so an untouched picker is always a no-op).
  • Download & Replace: picking an uninstalled language downloads its pack from docs-i18n into DATA_DIR/doc-packs/<lang> — manifest first, then every file verified against a sha256 + byte size, written to a temp dir, atomically swapped in — then the setting flips and the replaced language's pack is deleted (only one downloaded language on disk, ever). English is built-in and never downloaded or deleted. Live progress (n/123 files) shows in the button while downloading.
  • Robustness:
    • Downloads are pinned to the branch head's commit SHA (resolved via one GitHub API call) so the raw CDN can never serve a mixed manifest/file set after a translation push; if the API is unreachable it falls back to branch-ref URLs where hash checks still guarantee integrity.
    • Fetches go through safeFetch (https-only, reserved/private-IP blocking — the DOCS_I18N_BASE_URL override for forks/mirrors can't become an SSRF vector), downloads are gated to the static supported-language list, and manifests get archive-grade path validation (traversal, Windows drive/ADS colons, case-folded duplicates, size caps).
    • Crashed installs leave only .tmp-/.old- folders that are swept at startup, install start, and Fix. A half-written pack can never serve: the manifest lands last and marks a pack installed.
  • Fix button (shown when integrity breaks): full hash re-verification of the active pack, re-download when broken, sweep of crashed-install leftovers, deletion of any other language's pack, and reset-to-English only as a last resort when re-download is impossible.
  • The choice survives every update path (data dir is gitignored / volume-persisted): launcher updates, in-app Apply Update, installer reinstalls, docker compose pull. A new English doc that the pack doesn't cover yet simply serves in English with an EN badge (per-file fallback) — features are never blocked on translations.
  • Packs auto-refresh after updates: once per Engine build (APP_VERSION + git HEAD, so staging git updates count), the first start compares the selected pack against the docs-i18n manifest and re-downloads it if the translations changed; a stored choice whose pack is missing (downgrade, data restore) is restored the same way. Offline boots keep the installed pack serving and retry next start (documented in UPGRADING.md).
  • Search keeps the literal substring + hit-count contract over the active language. Translations follow a terminology glossary (one standardized Spanish term per concept; community loanwords like prompt/preset/lorebook/swipe kept) so searches hit consistently.

Drive-by fix

The shared markdown renderer accepted an indented code-fence opener but not an indented closer, so fences nested inside list items (e.g. docs/development/architecture-map.md § Migration rules) never closed and rendered their ``` markers as literal text. Close detection is now symmetric and, per CommonMark, the opener's indent is stripped from content lines so list-nested blocks don't render or copy phantom leading spaces. Column-zero fences (all chat content) are unchanged by construction.

New API surface

  • GET /api/docs, /search, /content: optional ?lang=, additive language fields; root now reports the active language's on-disk folder.
  • GET /api/docs/language — active/configured, supported languages with installed + coverage state, install progress (client polls at 1s during downloads), integrity flags. Never hashes on this path (cheap stat checks only).
  • PUT /api/docs/language — validated switch; downloads when needed (400 unsupported / 409 install-in-progress / 502 download-failed).
  • POST /api/docs/language/fix — the failsafe described above.
  • New env var DOCS_I18N_BASE_URL (documented in CONFIGURATION.md) for forks/mirrors.

Validation done

  • pnpm check green; reworked pnpm regression:docs lane (fixture pack in a temp DATA_DIR): two-root containment + traversal, manifest path-safety (zip-slip equivalents, case-folded dupes, size caps), truncation detection, build-manifest determinism, and a pinned invariant that doc content never renders via dangerouslySetInnerHTML (downloaded packs are less-trusted than in-repo docs).
  • Runtime-tested against a throwaway data dir: startup sweep, switch with leftover-pack deletion, Spanish serving/search from a materialized pack, corrupt-pack detection, Fix (failed re-download → clean reset + cleanup), 400/409/502 paths. The 502 test exercised the real raw.githubusercontent.com request path.
  • Translation QA: per-file structural verification, terminology-consistency sweeps, independent language-QA panel over 20 representative guides.
  • Two adversarial multi-agent review rounds; all confirmed findings fixed (including a tutorial-replay path that silently reverted the language, and the CDN manifest/file skew closed by commit pinning).

Summary by CodeRabbit

  • New Features

    • Added a Documentation Language setting with Spanish support.
    • Documentation packs download on demand, verify integrity, refresh automatically, and fall back to English when needed.
    • Added documentation language selection to onboarding.
    • Added English fallback badges and localized documentation viewer controls.
  • Bug Fixes

    • Improved rendering of indented and nested code blocks.
    • Fixed phantom indentation when copying code.
  • Documentation

    • Added guidance for maintaining translated documentation and configuring translation sources.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4100 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/25/2026 **Status:** ✅ Merged **Merged:** 7/25/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `agent/docs-language-es` --- ### 📝 Commits (9) - [`4023dfd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4023dfdaf2e879c050917ff87f43310ea4267eba) Add Documentation Language selector with per-file English fallback - [`a2a3ce5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a2a3ce559318ae06468f087656b5fa57fa8a2515) Add Spanish (es) translations for all user-facing docs - [`6597c02`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6597c02b9dc2e603ded4c6061b177a2744541684) Rework Documentation Language to download-on-demand packs - [`12195c8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/12195c81b7002a4c95a1e4ca32e90faa1cec8676) Harden docs pack switching from second review round - [`04bb884`](https://github.com/Pasta-Devs/Marinara-Engine/commit/04bb884e900517d8f6d66e109b4fcea63394b714) Auto-refresh the selected docs pack after Engine updates - [`039186f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/039186fa2d117966ffaa995933ac130852ee4e5e) Render indented code fences correctly in shared markdown - [`3717caa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3717caadf189e41f2ec603225ba81457df94d664) Add Documentation Language feature to the changelog - [`5a8a400`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5a8a4002233f7f9760503ce645283bb5b251c0be) Merge remote-tracking branch 'origin/staging' into agent/docs-language-es - [`5d3e93c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d3e93c3bae63d98d1dc3be110d470175419a743) Reference #4100 in the changelog entries ### 📊 Changes **22 files changed** (+1782 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `.github/pull_request_template.md` (+1 -0) 📝 `AGENTS.md` (+1 -0) 📝 `CHANGELOG.md` (+3 -0) 📝 `CLAUDE.md` (+1 -0) 📝 `CONTRIBUTING.md` (+8 -0) 📝 `docs/CONFIGURATION.md` (+1 -0) 📝 `docs/UPGRADING.md` (+2 -0) 📝 `package.json` (+2 -1) 📝 `packages/client/src/components/modals/DocsViewerModal.tsx` (+63 -12) 📝 `packages/client/src/components/onboarding/OnboardingTutorial.tsx` (+99 -4) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+156 -0) ➕ `packages/client/src/hooks/use-docs-language.ts` (+99 -0) 📝 `packages/client/src/hooks/use-docs.ts` (+40 -14) 📝 `packages/client/src/lib/markdown.tsx` (+11 -2) 📝 `packages/client/src/localization/locales/en.json` (+23 -0) 📝 `packages/server/src/routes/docs.routes.ts` (+370 -15) ➕ `packages/server/src/services/docs/docs-pack.service.ts` (+483 -0) ➕ `packages/shared/src/constants/docs-languages.ts` (+30 -0) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `scripts/docs-i18n/build-manifest.mjs` (+82 -0) _...and 2 more files_ </details> ### 📄 Description ## Why International users currently get English-only in-app guides. This PR adds a **Documentation Language** setting (Settings › General, plus a final step in the onboarding tutorial) with **download-on-demand language packs**, and ships the first full translation: **Spanish**, covering all 123 guides (developer docs included, so non-English-speaking contributors can build PRs and extensions too). Packs live on the companion **`docs-i18n` orphan branch** — never in user checkouts. Launchers only fetch `main`/`staging` and the installer clones a single tag, so translations add **zero checkout/image size**: important for Termux and thin-client installs as FIGS(P)/CJK land later (~1.3 MB per language ≈ 13 MB at ten languages, downloaded at most once by the users who want it). ## How it works - **Selector**: Settings › General › Documentation Language (below the UI-language selector; findable via settings search) and a dedicated final onboarding step (pre-selects the UI language on fresh installs; on replays it pre-selects the user's existing choice, so an untouched picker is always a no-op). - **Download & Replace**: picking an uninstalled language downloads its pack from `docs-i18n` into `DATA_DIR/doc-packs/<lang>` — manifest first, then every file verified against a **sha256 + byte size**, written to a temp dir, atomically swapped in — then the setting flips and **the replaced language's pack is deleted** (only one downloaded language on disk, ever). English is built-in and never downloaded or deleted. Live progress (`n/123 files`) shows in the button while downloading. - **Robustness**: - Downloads are **pinned to the branch head's commit SHA** (resolved via one GitHub API call) so the raw CDN can never serve a mixed manifest/file set after a translation push; if the API is unreachable it falls back to branch-ref URLs where hash checks still guarantee integrity. - Fetches go through `safeFetch` (https-only, reserved/private-IP blocking — the `DOCS_I18N_BASE_URL` override for forks/mirrors can't become an SSRF vector), downloads are gated to the static supported-language list, and manifests get archive-grade path validation (traversal, Windows drive/ADS colons, case-folded duplicates, size caps). - Crashed installs leave only `.tmp-`/`.old-` folders that are swept at startup, install start, and Fix. A half-written pack can never serve: the manifest lands last and marks a pack installed. - **Fix button** (shown when integrity breaks): full hash re-verification of the active pack, **re-download** when broken, sweep of crashed-install leftovers, **deletion of any other language's pack**, and reset-to-English only as a last resort when re-download is impossible. - **The choice survives every update path** (data dir is gitignored / volume-persisted): launcher updates, in-app Apply Update, installer reinstalls, `docker compose pull`. A new English doc that the pack doesn't cover yet simply serves in English with an `EN` badge (per-file fallback) — features are never blocked on translations. - **Packs auto-refresh after updates**: once per Engine build (APP_VERSION + git HEAD, so staging git updates count), the first start compares the selected pack against the `docs-i18n` manifest and re-downloads it if the translations changed; a stored choice whose pack is missing (downgrade, data restore) is restored the same way. Offline boots keep the installed pack serving and retry next start (documented in UPGRADING.md). - **Search** keeps the literal substring + hit-count contract over the active language. Translations follow a terminology glossary (one standardized Spanish term per concept; community loanwords like *prompt/preset/lorebook/swipe* kept) so searches hit consistently. ## Drive-by fix The shared markdown renderer accepted an indented code-fence *opener* but not an indented *closer*, so fences nested inside list items (e.g. `docs/development/architecture-map.md` § Migration rules) never closed and rendered their ` ``` ` markers as literal text. Close detection is now symmetric and, per CommonMark, the opener's indent is stripped from content lines so list-nested blocks don't render or copy phantom leading spaces. Column-zero fences (all chat content) are unchanged by construction. ## New API surface - `GET /api/docs`, `/search`, `/content`: optional `?lang=`, additive `language` fields; `root` now reports the active language's on-disk folder. - `GET /api/docs/language` — active/configured, supported languages with installed + coverage state, install progress (client polls at 1s during downloads), integrity flags. Never hashes on this path (cheap stat checks only). - `PUT /api/docs/language` — validated switch; downloads when needed (400 unsupported / 409 install-in-progress / 502 download-failed). - `POST /api/docs/language/fix` — the failsafe described above. - New env var `DOCS_I18N_BASE_URL` (documented in CONFIGURATION.md) for forks/mirrors. ## Validation done - `pnpm check` green; reworked `pnpm regression:docs` lane (fixture pack in a temp DATA_DIR): two-root containment + traversal, manifest path-safety (zip-slip equivalents, case-folded dupes, size caps), truncation detection, build-manifest determinism, and a pinned invariant that doc content never renders via `dangerouslySetInnerHTML` (downloaded packs are less-trusted than in-repo docs). - Runtime-tested against a throwaway data dir: startup sweep, switch with leftover-pack deletion, Spanish serving/search from a materialized pack, corrupt-pack detection, Fix (failed re-download → clean reset + cleanup), 400/409/502 paths. The 502 test exercised the real `raw.githubusercontent.com` request path. - Translation QA: per-file structural verification, terminology-consistency sweeps, independent language-QA panel over 20 representative guides. - Two adversarial multi-agent review rounds; all confirmed findings fixed (including a tutorial-replay path that silently reverted the language, and the CDN manifest/file skew closed by commit pinning). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a Documentation Language setting with Spanish support. * Documentation packs download on demand, verify integrity, refresh automatically, and fall back to English when needed. * Added documentation language selection to onboarding. * Added English fallback badges and localized documentation viewer controls. * **Bug Fixes** * Improved rendering of indented and nested code blocks. * Fixed phantom indentation when copying code. * **Documentation** * Added guidance for maintaining translated documentation and configuring translation sources. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:08:26 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6234
No description provided.