mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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.
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
// 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));
|
|
}
|