ai-yuca 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/transKey.js +27 -7
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/transKey.js
CHANGED
|
@@ -115,24 +115,44 @@ async function transKey(options) {
|
|
|
115
115
|
// 读取旧文件
|
|
116
116
|
const oldFilePath = path.join(oldFilesDir, fileName);
|
|
117
117
|
let oldData = {};
|
|
118
|
+
// 读取 keysDir 下的文件 (主翻译文件)
|
|
118
119
|
if (fs.existsSync(oldFilePath)) {
|
|
119
120
|
try {
|
|
120
121
|
oldData = JSON.parse(fs.readFileSync(oldFilePath, 'utf8'));
|
|
121
|
-
// console.log(`读取旧文件: ${oldFilePath}`);
|
|
122
122
|
}
|
|
123
123
|
catch (e) {
|
|
124
|
-
console.warn(
|
|
124
|
+
console.warn(`无法解析主翻译文件: ${oldFilePath}`);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
// 读取 source 下的旧文件 (如果存在)
|
|
128
|
+
const sourceFilePath = path.join(outputDir, fileName);
|
|
129
|
+
let sourceData = {};
|
|
130
|
+
if (fs.existsSync(sourceFilePath)) {
|
|
131
|
+
try {
|
|
132
|
+
sourceData = JSON.parse(fs.readFileSync(sourceFilePath, 'utf8'));
|
|
133
|
+
let hasChange = false;
|
|
134
|
+
// 将 source 中的翻译合并到 oldData (如果 oldData 中没有,或者 source 中有值而 oldData 为空)
|
|
135
|
+
for (const key in sourceData) {
|
|
136
|
+
if (sourceData[key] && !oldData[key]) {
|
|
137
|
+
oldData[key] = sourceData[key];
|
|
138
|
+
hasChange = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (hasChange) {
|
|
142
|
+
fs.writeFileSync(oldFilePath, JSON.stringify(oldData, null, 2), 'utf8');
|
|
143
|
+
console.log(`♻️ 已将 source 中的翻译整合回: ${oldFilePath}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
console.warn(`无法解析 source 文件: ${sourceFilePath}`);
|
|
148
|
+
}
|
|
129
149
|
}
|
|
130
|
-
// 生成新数据
|
|
150
|
+
// 生成新数据 (输出到 source 目录)
|
|
131
151
|
const newData = {};
|
|
132
152
|
const sortedKeys = Array.from(keys).sort();
|
|
133
153
|
let matchedCount = 0;
|
|
134
154
|
for (const key of sortedKeys) {
|
|
135
|
-
//
|
|
155
|
+
// 优先使用整合后的 oldData
|
|
136
156
|
if (oldData[key]) {
|
|
137
157
|
newData[key] = oldData[key];
|
|
138
158
|
matchedCount++;
|
|
@@ -141,7 +161,7 @@ async function transKey(options) {
|
|
|
141
161
|
newData[key] = '';
|
|
142
162
|
}
|
|
143
163
|
}
|
|
144
|
-
//
|
|
164
|
+
// 写入文件到 source 目录
|
|
145
165
|
fs.writeFileSync(outputPath, JSON.stringify(newData, null, 2), 'utf8');
|
|
146
166
|
console.log(`✅ 生成 ${fileName}: 总 Key 数 ${sortedKeys.length}, 已翻译 ${matchedCount}`);
|
|
147
167
|
}
|