refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* scripts/extract-i18n-domain.mjs
|
||||
* 从 i18n.ts 内联 messages 提取指定域至 locales/{locale}/{domain}.json 并移除内联键。
|
||||
*
|
||||
* Usage: node scripts/extract-i18n-domain.mjs <domain>
|
||||
* Example: node scripts/extract-i18n-domain.mjs workspace
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const domain = process.argv[2];
|
||||
if (!domain) {
|
||||
console.error('Usage: node scripts/extract-i18n-domain.mjs <domain>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(__dirname, '..');
|
||||
const i18nPath = path.resolve(root, 'src/i18n.ts');
|
||||
const localesRoot = path.resolve(root, 'src/locales');
|
||||
const locales = ['en', 'zh-CN', 'zh-TW', 'th'];
|
||||
|
||||
const content = fs.readFileSync(i18nPath, 'utf8');
|
||||
const start = content.indexOf('const messages = {') + 'const messages = '.length;
|
||||
const end = content.indexOf('const i18n = createI18n');
|
||||
const messagesStr = content.slice(start, end).trim().replace(/,\s*$/, '');
|
||||
const messages = new Function(`return ${messagesStr}`)();
|
||||
|
||||
for (const locale of locales) {
|
||||
const block = messages[locale]?.[domain];
|
||||
if (!block) {
|
||||
console.error(`Missing messages.${locale}.${domain}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const outDir = path.join(localesRoot, locale);
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
const outPath = path.join(outDir, `${domain}.json`);
|
||||
fs.writeFileSync(outPath, `${JSON.stringify(block, null, 2)}\n`, 'utf8');
|
||||
delete messages[locale][domain];
|
||||
console.log(`Wrote ${path.relative(root, outPath)}`);
|
||||
}
|
||||
|
||||
const header = content.slice(0, content.indexOf('const messages = {'));
|
||||
const footer = content.slice(end);
|
||||
const serialized = JSON.stringify(messages, null, 2);
|
||||
const newContent = `${header}const messages = ${serialized};\n\n${footer}`;
|
||||
fs.writeFileSync(i18nPath, newContent, 'utf8');
|
||||
console.log(`Stripped ${domain} from i18n.ts`);
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* scripts/strip-i18n-auth.mjs
|
||||
* 从 i18n.ts 内联 messages 中移除已外置至 locales 下 auth.json 的键。
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const i18nPath = path.resolve(__dirname, '../src/i18n.ts');
|
||||
|
||||
const content = fs.readFileSync(i18nPath, 'utf8');
|
||||
const start = content.indexOf('const messages = {') + 'const messages = '.length;
|
||||
const end = content.indexOf('const i18n = createI18n');
|
||||
const messagesStr = content.slice(start, end).trim().replace(/,\s*$/, '');
|
||||
const messages = new Function(`return ${messagesStr}`)();
|
||||
|
||||
for (const loc of ['en', 'zh-CN', 'zh-TW', 'th']) {
|
||||
delete messages[loc].title;
|
||||
delete messages[loc].login;
|
||||
delete messages[loc].landing;
|
||||
delete messages[loc].register;
|
||||
}
|
||||
|
||||
const header = content.slice(0, content.indexOf('const messages = {'));
|
||||
const footer = content.slice(end);
|
||||
const serialized = JSON.stringify(messages, null, 2);
|
||||
const newContent = `${header}const messages = ${serialized};\n\n${footer}`;
|
||||
fs.writeFileSync(i18nPath, newContent, 'utf8');
|
||||
console.log('Stripped auth keys from i18n.ts');
|
||||
Reference in new issue
Block a user