// collect-chinese.js const glob = require('glob'); const fs = require('fs'); const path = require('path'); const projectPath = './sheep'; // 修改为你的项目路径 const outputPath = './zh-cn-sheep-config.json'; // 配置表输出路径 const chineseRegex = /['"`]([^'"`\n]*[\u4e00-\u9fa5]+[^'"`\n]*)['"`]/g; let configObject = {}; function collectChinese() { try { const files = glob.sync(`${projectPath}/**/*.{js,vue,ts,html}`); files.forEach((file) => { const content = fs.readFileSync(file, 'utf8'); let match; while ((match = chineseRegex.exec(content)) !== null) { const chineseText = match[1]; if (!configObject[chineseText]) { configObject[chineseText] = ''; } } }); saveConfigFile(); } catch (err) { console.error('Error while scanning files:', err); } } function saveConfigFile() { const sortedConfig = Object.keys(configObject).sort().reduce((obj, key) => { obj[key] = configObject[key]; return obj; }, {}); fs.writeFileSync(outputPath, JSON.stringify(sortedConfig, null, 2)); console.log(`Config file saved to ${outputPath}`); } collectChinese();