feat(i18n): 21-language pipeline, landing/docs/API wiring, landing+API translations

Shared Claude Code translation pipeline (scripts/i18n, no API key) plus Astro/VitePress/Scalar i18n wiring. Landing and API reference translated into all 20 languages; docs i18n wiring + English source anchors. The translated docs markdown (apps/docs/<locale>/**, 3,620 files) follows in a companion PR because it exceeds GitHub's per-PR CI file limit.
This commit is contained in:
SnapOtter
2026-07-11 13:01:55 +08:00
committed by GitHub
parent 2e91368816
commit 00b651c9f8
353 changed files with 564607 additions and 2594 deletions
+35
View File
@@ -0,0 +1,35 @@
// apps/landing/src/lib/i18n-page.ts
import { getRelativeLocaleUrl } from "astro:i18n";
import { isRtl, LANDING_LOCALES } from "@/i18n";
/** Absolute site origin used for canonical + hreflang hrefs. */
export const SITE = "https://snapotter.com";
/** Prefix a path for a locale ("/faq" -> "/de/faq" for de, "/faq" for en). */
export function localizeHref(locale: string, path: string): string {
const clean = path.startsWith("/") ? path.slice(1) : path;
return getRelativeLocaleUrl(locale, clean);
}
/** Direction attribute for the current locale. */
export function dirFor(locale: string): "ltr" | "rtl" {
return isRtl(locale) ? "rtl" : "ltr";
}
/**
* Reciprocal hreflang alternates for one page path (same path across all locales),
* plus an x-default pointing at English.
*/
export function altLinks(path: string): Array<{ hreflang: string; href: string }> {
const links = LANDING_LOCALES.map((code) => ({
hreflang: code,
href: `${SITE}${localizeHref(code, path)}`,
}));
links.push({ hreflang: "x-default", href: `${SITE}${localizeHref("en", path)}` });
return links;
}
/** BCP-47-ish og:locale value ("de" -> "de", "pt-BR" -> "pt_BR"). */
export function ogLocale(locale: string): string {
return locale.replace("-", "_");
}
+36
View File
@@ -0,0 +1,36 @@
// apps/landing/src/lib/seo-content.ts
import { SUPPORTED_LOCALES } from "@snapotter/shared";
// Eager glob of every generated locale alternatives file. Missing files simply
// do not appear, so lookups fall back to the English source passed by the caller.
// Only the alternatives pages are localized; tool-detail pages are English-only.
const altFiles = import.meta.glob<{ default: Record<string, { text: string }> }>(
"../data/i18n/alternatives.*.json",
{ eager: true },
);
function catalog(
files: Record<string, { default: Record<string, { text: string }> }>,
base: string,
locale: string,
) {
return files[`../data/i18n/${base}.${locale}.json`]?.default ?? {};
}
/** Native/tool locale codes, from shared. */
export const SEO_LOCALES = SUPPORTED_LOCALES.map((l) => l.code);
/**
* Look up a translated alternatives string by id, falling back to the English source.
* `id` matches the landing-seo adapter ids ("alt:<slug>:<field>").
*/
export function seoText(locale: string, id: string, englishFallback: string): string {
if (locale === "en") return englishFallback;
return catalog(altFiles, "alternatives", locale)[id]?.text ?? englishFallback;
}
/** Translate an indexed array field, falling back per-item to the English source array. */
export function seoArray(locale: string, base: string, field: string, english: string[]): string[] {
if (locale === "en") return english;
return english.map((en, i) => seoText(locale, `${base}:${field}.${i}`, en));
}
+13
View File
@@ -0,0 +1,13 @@
// apps/landing/src/lib/tool-strings.ts
import { loadTranslations } from "@snapotter/shared";
/** Translated tool name/description for a locale, keyed by toolId. */
export async function loadToolStrings(
locale: string,
): Promise<Record<string, { name: string; description: string }>> {
const dict = await loadTranslations(locale);
return (
(dict as unknown as { tools?: Record<string, { name: string; description: string }> }).tools ??
{}
);
}