Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
import { readFile, writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
const root = fileURLToPath(new URL('../', import.meta.url));
const catalog = JSON.parse(await readFile(new URL('../assets/creator-languages/catalog.json', import.meta.url), 'utf8'));
const profiles = JSON.parse(await readFile(new URL('../assets/creator-languages/transcription-profiles.json', import.meta.url), 'utf8'));
const codes = new Set();
const aliases = new Set();
for (const item of catalog.languages) {
if (!/^[a-z][a-z_]+$/.test(item.code) || codes.has(item.code)) throw new Error(`Invalid/duplicate language: ${item.code}`);
codes.add(item.code);
for (const field of ['nativeName', 'englishName', 'chineseName', 'script']) if (!item[field]) throw new Error(`Missing ${field}: ${item.code}`);
if (!['ltr', 'rtl'].includes(item.direction)) throw new Error(`Invalid direction: ${item.code}`);
for (const alias of item.aliases) {
if (aliases.has(alias)) throw new Error(`Duplicate alias: ${alias}`);
aliases.add(alias);
}
}
for (const alias of aliases) if (codes.has(alias)) throw new Error(`Alias shadows language: ${alias}`);
for (const code of profiles.whisperV3) if (!codes.has(code)) throw new Error(`Unknown ASR language: ${code}`);
const ts = `// Generated by scripts/generate-creator-languages.mjs. Do not edit.\nexport const creatorLanguages = ${JSON.stringify(catalog.languages, null, 2)} as const;\nexport const creatorTranscriptionProfiles = ${JSON.stringify(profiles, null, 2)} as const;\n`;
const quote = JSON.stringify;
// Keep the canonical Go layout here so Web/protocol builds need only Node.
const go = `// Code generated by scripts/generate-creator-languages.mjs; DO NOT EDIT.\npackage types\n\nvar LanguageCatalog = []LanguageMetadata{\n${catalog.languages.map(l => `\t{Code: ${quote(l.code)}, NativeName: ${quote(l.nativeName)}, EnglishName: ${quote(l.englishName)}, ChineseName: ${quote(l.chineseName)}, Script: ${quote(l.script)}, Direction: ${quote(l.direction)}, WordSpaces: ${l.wordSpaces}, SourcePreferred: ${l.sourcePreferred}, Speech: ${l.speech}, Aliases: []string{${l.aliases.map(quote).join(', ')}}},`).join('\n')}\n}\n`;
const formattedGo = go + `\nconst WhisperProfileVersion = ${quote(profiles.version)}\n\nvar WhisperV2Languages = []string{${profiles.whisperV2.map(quote).join(', ')}}\nvar WhisperV3Languages = []string{${profiles.whisperV3.map(quote).join(', ')}}\n`;
for (const [path, content] of [
['packages/protocol/src/creator-languages.generated.ts', ts],
['runtime/krillinai/internal/types/language_catalog.generated.go', formattedGo]
]) {
const url = new URL(path, `file://${root}`);
if (process.argv.includes('--check')) {
if (await readFile(url, 'utf8').catch(() => '') !== content) throw new Error(`Stale generated language catalog: ${path}`);
} else await writeFile(url, content);
}