mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-06-11 19:07:01 +00:00
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.
This commit is contained in:
64
web/i18n/loadMessages.ts
Normal file
64
web/i18n/loadMessages.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
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())
|
||||
}
|
||||
14
web/i18n/navigation.ts
Normal file
14
web/i18n/navigation.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { createNavigation } from "next-intl/navigation"
|
||||
import { routing } from "./routing"
|
||||
|
||||
/**
|
||||
* Locale-aware wrappers around `next/link`, `next/navigation` and
|
||||
* server-side `redirect()`. Import from here instead of `next/link`
|
||||
* for internal hrefs — these helpers automatically prepend the active
|
||||
* `[locale]` segment, so a component can write `<Link href="/docs">`
|
||||
* and the user sees `/en/docs` or `/es/docs` depending on context.
|
||||
*
|
||||
* External URLs and anchors (`href="#section"`) are left untouched.
|
||||
*/
|
||||
export const { Link, redirect, usePathname, useRouter, getPathname } =
|
||||
createNavigation(routing)
|
||||
63
web/i18n/request.ts
Normal file
63
web/i18n/request.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { hasLocale } from "next-intl"
|
||||
import { getRequestConfig } from "next-intl/server"
|
||||
import { routing } from "./routing"
|
||||
import { loadMessages } from "./loadMessages"
|
||||
|
||||
/**
|
||||
* Per-request i18n config consumed by next-intl on every page render.
|
||||
*
|
||||
* Loads the entire translation tree for the active locale by walking
|
||||
* `messages/<locale>/` (see loadMessages.ts). Conventions:
|
||||
*
|
||||
* - `common.json` / `index.json` → keys merged at root
|
||||
* - `<name>.json` → namespace `<name>.*`
|
||||
* - sub-directories → nested namespace
|
||||
*
|
||||
* Missing translations transparently fall back to English. When a
|
||||
* translator hasn't finished a section yet the user sees the English
|
||||
* text instead of a broken `MISSING_MESSAGE` placeholder.
|
||||
*/
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
const requested = await requestLocale
|
||||
const locale = hasLocale(routing.locales, requested)
|
||||
? requested
|
||||
: routing.defaultLocale
|
||||
|
||||
const enMessages = loadMessages("en")
|
||||
const localeMessages = locale === "en" ? {} : loadMessages(locale)
|
||||
|
||||
return {
|
||||
locale,
|
||||
messages: deepMerge(enMessages, localeMessages),
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Deep-merge two message trees so the locale's translations override
|
||||
* the English defaults while still falling back to English for any
|
||||
* key the translator hasn't filled in yet.
|
||||
*/
|
||||
function deepMerge(
|
||||
base: Record<string, unknown>,
|
||||
override: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
const out: Record<string, unknown> = { ...base }
|
||||
for (const [k, v] of Object.entries(override)) {
|
||||
if (
|
||||
v &&
|
||||
typeof v === "object" &&
|
||||
!Array.isArray(v) &&
|
||||
typeof out[k] === "object" &&
|
||||
out[k] !== null &&
|
||||
!Array.isArray(out[k])
|
||||
) {
|
||||
out[k] = deepMerge(
|
||||
out[k] as Record<string, unknown>,
|
||||
v as Record<string, unknown>,
|
||||
)
|
||||
} else {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
27
web/i18n/routing.ts
Normal file
27
web/i18n/routing.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineRouting } from "next-intl/routing"
|
||||
|
||||
/**
|
||||
* i18n routing configuration for the ProxMenux web docs.
|
||||
*
|
||||
* - English is the default locale: the docs grew up in English and the
|
||||
* homelab/Proxmox audience is primarily international. New locales
|
||||
* land progressively; missing translations should fall back to the
|
||||
* English message rather than 404.
|
||||
*
|
||||
* - `localePrefix: "always"` is required for `output: "export"` static
|
||||
* builds and gives cleaner SEO: every URL carries an explicit locale
|
||||
* segment (`/en/docs/...`, `/es/docs/...`) so hreflang and Google's
|
||||
* per-language indexing work without ambiguity.
|
||||
*
|
||||
* - When adding a new locale here, also create
|
||||
* `messages/<locale>/common.json` (mandatory) and start
|
||||
* page-specific files under `messages/<locale>/docs/...`. See
|
||||
* `CONTRIBUTING-TRANSLATIONS.md`.
|
||||
*/
|
||||
export const routing = defineRouting({
|
||||
locales: ["en", "es"],
|
||||
defaultLocale: "en",
|
||||
localePrefix: "always",
|
||||
})
|
||||
|
||||
export type Locale = (typeof routing.locales)[number]
|
||||
Reference in New Issue
Block a user