Files
ProxMenux/web/i18n/loadMessages.ts
T
MacRimi 5ca3463bf6 complete i18n migration to /[locale]/ with EN+ES content
Full rewrite of the docs site under app/[locale]/ with next-intl
in localePrefix:"always" mode. Every page now exists at both
/en/<path> and /es/<path>; the root / shows a meta-refresh + JS
redirect to /<defaultLocale>/ so GitHub Pages serves something
on the apex URL.

Highlights:
- 107 doc pages migrated to file-per-page JSON namespaces under
  messages/en/ and messages/es/. Spanish content is fully
  translated (no copy-of-English placeholders).
- New documentation for the Active Suppressions section in the
  Settings tab and the per-event Dismiss dropdown in the Health
  Monitor modal.
- New screenshots: dismiss-duration-dropdown.png and an updated
  health-suppression-settings.png.
- Pagefind integrated for client-side search; index is built on
  every CI deploy (not committed).
- RSS feeds: per-locale at /<locale>/rss.xml plus root /rss.xml
  for backward compat.
- Removed the dead app/[locale]/guides/[slug]/ route — every
  guide now has its own static page and no markdown source
  remains.
- Fixed orphan link /guides/nvidia -> /guides/nvidia-manual in
  docs/hardware/nvidia-host.
- Removed obsolete components (footer2, calendar, drawer).

Verified locally with `npm ci && npm run build`: 2804 files in
out/, 231 pages indexed by pagefind, root redirect intact, both
locale roots and the new Active Suppressions docs render OK.
2026-05-31 12:41:10 +02:00

65 lines
2.1 KiB
TypeScript

import fs from "fs"
import path from "path"
/**
* Recursively load every translation JSON under `messages/<locale>/`
* and assemble them into a single nested object that next-intl can
* read via `useTranslations(namespace)`.
*
* Convention:
* - `common.json` or `index.json` at any folder → its keys are merged
* at the current level (no extra namespace).
* - any other `<name>.json` → its content becomes a nested key under
* `<name>`.
* - subdirectories become nested keys themselves.
*
* Example:
* messages/en/common.json → root (nav.home, footer.*)
* messages/en/docs/monitor/index.json → docs.monitor.*
* messages/en/docs/monitor/access-auth.json → docs.monitor.accessAuth.*
*
* This runs at build time (Next.js `getRequestConfig` is invoked during
* static generation under `output: "export"`) so the filesystem walk is
* fine — no runtime cost.
*/
export function loadMessages(locale: string): Record<string, unknown> {
const root = path.join(process.cwd(), "messages", locale)
if (!fs.existsSync(root)) return {}
return readDir(root)
}
function readDir(dir: string): Record<string, unknown> {
const out: Record<string, unknown> = {}
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) {
// Sub-directory becomes a nested namespace keyed by its name,
// with a kebab-to-camelCase conversion so the JS API stays
// ergonomic (e.g. access-auth → accessAuth).
const key = toCamel(entry.name)
out[key] = readDir(fullPath)
continue
}
if (!entry.name.endsWith(".json")) continue
const parsed = JSON.parse(fs.readFileSync(fullPath, "utf-8"))
const base = entry.name.replace(/\.json$/, "")
if (base === "common" || base === "index") {
// Merge at the current level — no extra namespace.
Object.assign(out, parsed)
} else {
out[toCamel(base)] = parsed
}
}
return out
}
function toCamel(name: string): string {
return name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase())
}