mirror of
https://github.com/lobehub/lobehub.git
synced 2026-09-20 04:56:13 +08:00
d13f2e3ad8
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { consola } from 'consola';
|
|
import { colors } from 'consola/utils';
|
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
import { dirname } from 'node:path';
|
|
|
|
import { entryLocaleJsonFilepath, i18nConfig, localeDir, srcDefaultLocales } from './const';
|
|
import { tagWhite, writeJSON } from './utils';
|
|
|
|
export const genDefaultLocale = () => {
|
|
consola.info(`Default locale: ${i18nConfig.entryLocale}...`);
|
|
|
|
// Ensure entry locale directory exists
|
|
const entryLocaleDir = localeDir(i18nConfig.entryLocale);
|
|
if (!existsSync(entryLocaleDir)) {
|
|
mkdirSync(entryLocaleDir, { recursive: true });
|
|
consola.info(`Creating directory: ${entryLocaleDir}`);
|
|
}
|
|
|
|
const resources = require(srcDefaultLocales);
|
|
const data = Object.entries(resources.default);
|
|
consola.start(`Generating default locale JSON files, found ${data.length} namespaces...`);
|
|
|
|
for (const [ns, value] of data) {
|
|
const filepath = entryLocaleJsonFilepath(`${ns}.json`);
|
|
|
|
// Ensure directory exists
|
|
const dir = dirname(filepath);
|
|
if (!existsSync(dir)) {
|
|
mkdirSync(dir, { recursive: true });
|
|
}
|
|
|
|
writeJSON(filepath, value);
|
|
consola.success(tagWhite(ns), colors.gray(filepath));
|
|
}
|
|
};
|