Files
youtube-generator/scripts/validate-locales.ts
T
poli0981andClaude Opus 4.6 a763f7c78a feat: Phase 1 MVP scaffold — core engine, i18n, UI, CI/CD
Complete Phase 1 implementation of YTDescGen:
- Project setup: Vite 5 + React 18 + TypeScript strict + Tailwind CSS dark theme
- Config layer: 7 video types, 10 genres, 7 platforms, rig/social fields
- i18n: EN/VI/JA with separate UI and template namespaces + validation script
- Core engine: title-builder, description-builder, tag-generator (pure TS, zero React)
- 42 unit tests covering all engine functions
- Zustand stores: editor + settings with localStorage persistence
- UI: 6 primitives, 11 editor components, 4 output components, 3 layout components
- Pages: Editor (form + quick preview) and Output (title/desc/tags + copy)
- CI/CD: GitHub Actions for lint/typecheck/test/build + GitHub Pages deploy

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:46:59 +07:00

98 lines
2.9 KiB
TypeScript

import { readFileSync, readdirSync, existsSync } from "fs";
import { join, resolve } from "path";
const LOCALES_DIR = resolve("src/i18n/locales");
const SCHEMA_PATH = join(LOCALES_DIR, "_schema.json");
interface Schema {
ui: Record<string, string[]>;
templates: Record<string, string[]>;
}
function getNestedKeys(obj: Record<string, unknown>, prefix = ""): string[] {
const keys: string[] = [];
for (const key of Object.keys(obj)) {
const fullKey = prefix ? `${prefix}.${key}` : key;
const value = obj[key];
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
keys.push(...getNestedKeys(value as Record<string, unknown>, fullKey));
} else {
keys.push(fullKey);
}
}
return keys;
}
function getExpectedKeys(schema: Schema, namespace: "ui" | "templates"): string[] {
const section = schema[namespace];
const keys: string[] = [];
for (const [path, fields] of Object.entries(section)) {
for (const field of fields) {
keys.push(`${path}.${field}`);
}
}
return keys;
}
function validate(): void {
if (!existsSync(SCHEMA_PATH)) {
console.error("Schema file not found:", SCHEMA_PATH);
process.exit(1);
}
const schema: Schema = JSON.parse(readFileSync(SCHEMA_PATH, "utf-8"));
const expectedUIKeys = getExpectedKeys(schema, "ui");
const expectedTemplateKeys = getExpectedKeys(schema, "templates");
const localeDirs = readdirSync(LOCALES_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => d.name);
let hasErrors = false;
for (const locale of localeDirs) {
const localeDir = join(LOCALES_DIR, locale);
for (const [filename, expectedKeys] of [
["ui.json", expectedUIKeys],
["templates.json", expectedTemplateKeys],
] as const) {
const filePath = join(localeDir, filename);
if (!existsSync(filePath)) {
console.error(`✗ ${locale}/${filename} — FILE MISSING`);
hasErrors = true;
continue;
}
const content: Record<string, unknown> = JSON.parse(readFileSync(filePath, "utf-8"));
const actualKeys = getNestedKeys(content);
const missing = expectedKeys.filter((k) => !actualKeys.includes(k));
const extra = actualKeys.filter((k) => !expectedKeys.includes(k));
if (missing.length === 0 && extra.length === 0) {
console.log(`✓ ${locale}/${filename} — ${actualKeys.length}/${expectedKeys.length} keys`);
} else {
hasErrors = true;
console.error(
`✗ ${locale}/${filename} — ${actualKeys.length}/${expectedKeys.length} keys`,
);
if (missing.length > 0) {
console.error(` Missing: ${missing.join(", ")}`);
}
if (extra.length > 0) {
console.error(` Extra: ${extra.join(", ")}`);
}
}
}
}
if (hasErrors) {
process.exit(1);
} else {
console.log("\nAll locale files are complete!");
}
}
validate();