mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(packages): i18n (#1708)
This commit is contained in:
@@ -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);
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user