All files / src/lib/docs published-docs-i18n.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                    309x 58x                   3x    
/**
 * The translations of the published documents (ADR-071): which languages
 * each document has and whether each is current. The index is small and
 * bundled; the translated bodies are files under public/, fetched only when
 * a reader picks that language.
 *
 * Both are written by scripts/gen-docs-content.py from docs/i18n/<lang>/...;
 * a translation is "stale" when the English file changed after it was
 * translated (its sourceHash is no longer the English file's hash).
 */
import index from "@/content/published-docs-i18n.json";
import type { CatalogLanguage } from "@/lib/metadata-language";
import { BASE_PATH } from "@/lib/static-export";
 
export type TranslationStatus = "current" | "stale";
 
export interface DocTranslation {
  status: TranslationStatus;
  /** The document's title in that language, its first heading. */
  title: string;
  /** The one-line summary, when the translation's frontmatter has one. */
  summary?: string;
}
 
type Index = Record<string, Partial<Record<CatalogLanguage, DocTranslation>>>;
 
const DOCS = index.docs as Index;
 
/** The translation of one published document into a language, if any. */
export function translationOf(
  section: string,
  slug: string,
  lang: CatalogLanguage,
): DocTranslation | undefined {
  if (lang === "en") return undefined;
  return DOCS[`${section}/${slug}`]?.[lang];
}
 
/** Where the page fetches a translated body, under the static export's
 *  base path. */
export function translationUrl(
  section: string,
  slug: string,
  lang: CatalogLanguage,
): string {
  return `${BASE_PATH}/published-docs/i18n/${lang}/${section}/${slug}.json`;
}