i18-fe-automator-beta 1.0.7 → 1.0.8

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.
@@ -2029,7 +2029,7 @@ if (sass) {
2029
2029
  lint$1(lint, fix);
2030
2030
  } else if (lintc) {
2031
2031
  inquirer.prompt(rules).then(async ({ rule }) => {
2032
- const parentRule =rule;
2032
+ const parentRule = rule;
2033
2033
  if (rule === "currency") {
2034
2034
  const ruleChoice = rules.find((item) => item.name === "rule");
2035
2035
  const currencySubChoice = ruleChoice.choices.find(
@@ -2037,8 +2037,8 @@ if (sass) {
2037
2037
  ).children;
2038
2038
  const { scene } = await inquirer.prompt(currencySubChoice);
2039
2039
  rule = scene;
2040
- if(rule==='customColumnModule'){
2041
- return customColumnModule(lintc,fix,rule,parentRule)
2040
+ if (rule === "customColumnModule") {
2041
+ return customColumnModule(lintc, fix, rule, parentRule);
2042
2042
  }
2043
2043
  }
2044
2044
  lint$1(lintc, fix, rule);
@@ -2161,7 +2161,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2161
2161
  if (isOk) {
2162
2162
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2163
2163
  let key = newAllArr.find(
2164
- (item) => item.path === fPath && item.ZH_CN === p1
2164
+ (item) =>
2165
+ item.path === fPath &&
2166
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2165
2167
  ).key;
2166
2168
  // 去除{ slotxx }
2167
2169
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2204,7 +2206,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2204
2206
  groupArr = allArr;
2205
2207
  }
2206
2208
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2207
- if(!groupArr.length) return
2209
+ if (!groupArr.length) return;
2208
2210
  const task = groupArr.map(async (item, index) => {
2209
2211
  let str = "";
2210
2212
  item.forEach((item1, index1) => {
@@ -2219,11 +2221,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2219
2221
  groupArr.forEach((item, index) => {
2220
2222
  Array.prototype.push.apply(newAllArr, item);
2221
2223
  });
2224
+ // 如果中文不同,但翻译的英文相同(比如商品品类和商品类别翻译的英文都是Product Category),对key进行自动+1
2225
+ for (let i = 0; i < newAllArr.length; i++) {
2226
+ let num = 0;
2227
+ for (let j = 0; j < newAllArr.length; j++) {
2228
+ // key存在且不能为空
2229
+ if (newAllArr[j].key && newAllArr[i].key) {
2230
+ if (
2231
+ newAllArr[j].key === newAllArr[i].key &&
2232
+ newAllArr[j].ZH_CN !== newAllArr[i].ZH_CN
2233
+ ) {
2234
+ num++;
2235
+ newAllArr[j].key = newAllArr[j].key + num;
2236
+ }
2237
+ }
2238
+ }
2239
+ }
2222
2240
  readFolder(true);
2223
-
2241
+ // 如果key相等去重
2242
+ const uniqueArr = Array.from(
2243
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2244
+ );
2224
2245
  let exportData = [];
2225
2246
  // key中有debug排后面
2226
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2247
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2227
2248
  return item.key.indexOf("debug") > -1;
2228
2249
  });
2229
2250
  sortNewAllArr.forEach((item, index) => {
@@ -2288,7 +2309,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2288
2309
  }
2289
2310
  const buffer = xlsx.build([{ data: exportData }]);
2290
2311
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2291
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2312
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2292
2313
  });
2293
2314
  }
2294
2315
 
@@ -2317,9 +2338,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2317
2338
  if (resBody.trans_result) {
2318
2339
  console.log(`ok`);
2319
2340
  let result = resBody.trans_result || [];
2341
+
2320
2342
  item.forEach((item1, index1) => {
2321
2343
  const id = uuid.v5(item1.path, uuid.v5.URL).slice(0, 6);
2322
- if (result[index1] && result[index1].src === item1.ZH_CN) {
2344
+ if (
2345
+ result[index1] &&
2346
+ (result[index1].src === item1.ZH_CN ||
2347
+ result[index1].src === item1.ZH_CN.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2348
+ ) {
2323
2349
  // 删除str中的单引号或双引号或斜杠或逗号
2324
2350
  let str = result[index1].dst
2325
2351
  .replace(/\'/g, "")
@@ -2330,7 +2356,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2330
2356
  const s = str.split(" ");
2331
2357
  let key = s
2332
2358
  .map((item, index) => {
2333
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2359
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2334
2360
  })
2335
2361
  .join("");
2336
2362
  // 去除key中的标点符号
@@ -2007,7 +2007,7 @@ if (sass) {
2007
2007
  lint$1(lint, fix);
2008
2008
  } else if (lintc) {
2009
2009
  inquirer.prompt(rules).then(async ({ rule }) => {
2010
- const parentRule =rule;
2010
+ const parentRule = rule;
2011
2011
  if (rule === "currency") {
2012
2012
  const ruleChoice = rules.find((item) => item.name === "rule");
2013
2013
  const currencySubChoice = ruleChoice.choices.find(
@@ -2015,8 +2015,8 @@ if (sass) {
2015
2015
  ).children;
2016
2016
  const { scene } = await inquirer.prompt(currencySubChoice);
2017
2017
  rule = scene;
2018
- if(rule==='customColumnModule'){
2019
- return customColumnModule(lintc,fix,rule,parentRule)
2018
+ if (rule === "customColumnModule") {
2019
+ return customColumnModule(lintc, fix, rule, parentRule);
2020
2020
  }
2021
2021
  }
2022
2022
  lint$1(lintc, fix, rule);
@@ -2139,7 +2139,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2139
2139
  if (isOk) {
2140
2140
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2141
2141
  let key = newAllArr.find(
2142
- (item) => item.path === fPath && item.ZH_CN === p1
2142
+ (item) =>
2143
+ item.path === fPath &&
2144
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2143
2145
  ).key;
2144
2146
  // 去除{ slotxx }
2145
2147
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2182,7 +2184,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2182
2184
  groupArr = allArr;
2183
2185
  }
2184
2186
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2185
- if(!groupArr.length) return
2187
+ if (!groupArr.length) return;
2186
2188
  const task = groupArr.map(async (item, index) => {
2187
2189
  let str = "";
2188
2190
  item.forEach((item1, index1) => {
@@ -2197,11 +2199,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2197
2199
  groupArr.forEach((item, index) => {
2198
2200
  Array.prototype.push.apply(newAllArr, item);
2199
2201
  });
2202
+ // 如果中文不同,但翻译的英文相同(比如商品品类和商品类别翻译的英文都是Product Category),对key进行自动+1
2203
+ for (let i = 0; i < newAllArr.length; i++) {
2204
+ let num = 0;
2205
+ for (let j = 0; j < newAllArr.length; j++) {
2206
+ // key存在且不能为空
2207
+ if (newAllArr[j].key && newAllArr[i].key) {
2208
+ if (
2209
+ newAllArr[j].key === newAllArr[i].key &&
2210
+ newAllArr[j].ZH_CN !== newAllArr[i].ZH_CN
2211
+ ) {
2212
+ num++;
2213
+ newAllArr[j].key = newAllArr[j].key + num;
2214
+ }
2215
+ }
2216
+ }
2217
+ }
2200
2218
  readFolder(true);
2201
-
2219
+ // 如果key相等去重
2220
+ const uniqueArr = Array.from(
2221
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2222
+ );
2202
2223
  let exportData = [];
2203
2224
  // key中有debug排后面
2204
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2225
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2205
2226
  return item.key.indexOf("debug") > -1;
2206
2227
  });
2207
2228
  sortNewAllArr.forEach((item, index) => {
@@ -2266,7 +2287,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2266
2287
  }
2267
2288
  const buffer = xlsx.build([{ data: exportData }]);
2268
2289
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2269
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2290
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2270
2291
  });
2271
2292
  }
2272
2293
 
@@ -2295,9 +2316,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2295
2316
  if (resBody.trans_result) {
2296
2317
  console.log(`ok`);
2297
2318
  let result = resBody.trans_result || [];
2319
+
2298
2320
  item.forEach((item1, index1) => {
2299
2321
  const id = v5(item1.path, v5.URL).slice(0, 6);
2300
- if (result[index1] && result[index1].src === item1.ZH_CN) {
2322
+ if (
2323
+ result[index1] &&
2324
+ (result[index1].src === item1.ZH_CN ||
2325
+ result[index1].src === item1.ZH_CN.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2326
+ ) {
2301
2327
  // 删除str中的单引号或双引号或斜杠或逗号
2302
2328
  let str = result[index1].dst
2303
2329
  .replace(/\'/g, "")
@@ -2308,7 +2334,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2308
2334
  const s = str.split(" ");
2309
2335
  let key = s
2310
2336
  .map((item, index) => {
2311
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2337
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2312
2338
  })
2313
2339
  .join("");
2314
2340
  // 去除key中的标点符号
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18-fe-automator-beta",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "i18-fe-automator-beta内测版本,只用于key: ''替换、检测中文规则等",
5
5
  "type": "module",
6
6
  "bin": {