- 新增 I18nUtils 工具类提供多语言消息获取功能 - 创建多语言技术方案设计文档 MULTILANG_I18N_DESIGN.md - 编写国际化战略文章 HEALTHLINK_HIS_INTERNATIONALIZATION_STRATEGY.md - 添加国际化战略概述文档 HEALTHLINK_HIS_INTL_STRATEGY.md - 实现基于 MessageSource 的多语言消息处理机制 - 设计支持中英越三语的国际化架构方案 - 规划前端 vue-i18n 和后端 MessageSource 集成方案 - 定义数据库多语言表结构支持菜单和字典国际化 - 制定硬编码消息迁移策略和实施计划 - 建立多语言工作量评估和风险应对措施
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { execSync } = require('child_process');
|
|
|
|
const BASE = path.join(__dirname, '..', 'src', 'views', 'medicationmanagement');
|
|
const CWD = path.join(__dirname, '..', '..');
|
|
|
|
function walkDir(dir) {
|
|
const files = [];
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) files.push(...walkDir(fullPath));
|
|
else if (entry.name.endsWith('.vue')) files.push(fullPath);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function getOriginalContent(filePath) {
|
|
try {
|
|
const relPath = path.relative(CWD, filePath).replace(/\\/g, '/');
|
|
return execSync(`git show HEAD:"${relPath}"`, { encoding: 'utf8', cwd: CWD });
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const vueFiles = walkDir(BASE);
|
|
const translations = {};
|
|
|
|
for (const file of vueFiles) {
|
|
const content = fs.readFileSync(file, 'utf8');
|
|
const original = getOriginalContent(file);
|
|
if (!original) continue;
|
|
|
|
const currentLines = content.split('\n');
|
|
const originalLines = original.split('\n');
|
|
|
|
for (let i = 0; i < currentLines.length; i++) {
|
|
const line = currentLines[i];
|
|
// Find t('key') calls in this line
|
|
const tMatch = line.match(/t\('(medication\.[^']+)'\)/);
|
|
if (!tMatch) continue;
|
|
|
|
const key = tMatch[1];
|
|
if (translations[key]) continue; // Already mapped
|
|
|
|
// Look at the same line in the original file
|
|
if (i < originalLines.length) {
|
|
const origLine = originalLines[i];
|
|
// Find Chinese text in the original line
|
|
const chineseMatch = origLine.match(/"([^"]*[\u4e00-\u9fff][^"]*)"/);
|
|
if (chineseMatch) {
|
|
translations[key] = chineseMatch[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`Extracted ${Object.keys(translations).length} translation keys`);
|
|
|
|
// Write flat keys
|
|
const flatPath = path.join(__dirname, '..', 'src', 'i18n', 'locales', 'medication_keys_flat.json');
|
|
fs.writeFileSync(flatPath, JSON.stringify(translations, null, 2), 'utf8');
|
|
|
|
// Write structured keys
|
|
const outputPath = path.join(__dirname, '..', 'src', 'i18n', 'locales', 'medication_keys.json');
|
|
const output = {};
|
|
for (const [key, value] of Object.entries(translations)) {
|
|
const parts = key.split('.');
|
|
let current = output;
|
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
if (!current[parts[i]]) current[parts[i]] = {};
|
|
current = current[parts[i]];
|
|
}
|
|
current[parts[parts.length - 1]] = value;
|
|
}
|
|
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2), 'utf8');
|
|
|
|
console.log(`Wrote ${flatPath}`);
|
|
console.log(`Wrote ${outputPath}`);
|