feat(packages): i18n (#1708)

This commit is contained in:
Sam Potts
2026-07-10 12:58:47 +10:00
committed by GitHub
parent 5f48fcc6d6
commit 028dadb385
561 changed files with 13059 additions and 1320 deletions
@@ -0,0 +1,28 @@
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { LOCALES, localeAliases } from '@videojs/core/i18n';
const outPath = resolve(import.meta.dirname, '../app/shared/i18n/cdn-locale-loaders.generated.ts');
function localeObjectKey(tag: string): string {
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(tag) ? tag : `'${tag}'`;
}
const localePacks = [...LOCALES, ...localeAliases(LOCALES)];
const entries = localePacks
.sort((a, b) => a.localeCompare(b, 'en'))
.map((tag) => ` ${localeObjectKey(tag)}: () => import('@videojs/html/cdn/locales/${tag}'),`)
.join('\n');
const source = `/** Generated by scripts/generate-cdn-locale-loaders.ts — do not edit. */
import type { SandboxLocalePack } from './locale-meta';
/** CDN locale chunks register via \`../i18n.dev.js\` — same module graph as \`@videojs/html/cdn/video\`. */
export const cdnLocaleLoaders = {
${entries}
} as const satisfies Record<Exclude<SandboxLocalePack, 'en'>, () => Promise<unknown>>;
`;
writeFileSync(outPath, source);
+2
View File
@@ -1,5 +1,7 @@
import { mirrorTemplatesToSrc, removeGeneratedSrcFiles } from './shared.js';
await import('./generate-cdn-locale-loaders.ts');
const created = await mirrorTemplatesToSrc();
const removed = await removeGeneratedSrcFiles();
+8 -2
View File
@@ -18,6 +18,8 @@ export interface Change {
}
export function getChanges(): Change[] {
// `src/` is gitignored and generated from `templates/` on setup/build.
fs.ensureDirSync(SRC);
const res: Result = compareSync(SRC, TEMPLATES, { compareContent: true });
return (res.diffSet ?? [])
@@ -98,9 +100,13 @@ export async function mirrorTemplatesToSrc(): Promise<string[]> {
continue;
}
if (await fs.pathExists(targetPath)) continue;
if (await fs.pathExists(targetPath)) {
const existing = await fs.readFile(targetPath, 'utf8');
const next = await fs.readFile(templatePath, 'utf8');
if (existing === next) continue;
}
await fs.copy(templatePath, targetPath);
await fs.copy(templatePath, targetPath, { overwrite: true });
created.push(targetPath);
}
}