i18-fe-automator-beta 1.0.7 → 1.0.9

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.
@@ -100,8 +100,9 @@ function importExcel({ uploadFilePath, token, env }) {
100
100
  return new Promise((resolve, reject) => {
101
101
  request(
102
102
  {
103
- url: `https://${env === "pro" ? "" : `${env}-`
104
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
103
+ url: `https://${
104
+ env === "pro" ? "" : `${env}-`
105
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
105
106
  method: "POST",
106
107
  headers: {
107
108
  contentType: "multipart/form-data",
@@ -119,7 +120,9 @@ function importExcel({ uploadFilePath, token, env }) {
119
120
  resolve(true);
120
121
  } else {
121
122
  Loading$1.fail(`${env}: 导入文件失败`);
122
- console.log(chalk.red(error || JSON.stringify(res.data)));
123
+ console.log(
124
+ chalk.red(error || (res.data ? JSON.stringify(res.data) : res.msg))
125
+ );
123
126
  }
124
127
  }
125
128
  );
@@ -165,8 +168,9 @@ function uploadExcel({ data, token, env }) {
165
168
  return new Promise((resolve, reject) => {
166
169
  request(
167
170
  {
168
- url: `https://${env === "pro" ? "" : `${env}-`
169
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
171
+ url: `https://${
172
+ env === "pro" ? "" : `${env}-`
173
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
170
174
  method: "POST",
171
175
  json: true,
172
176
  headers: {
@@ -2029,7 +2033,7 @@ if (sass) {
2029
2033
  lint$1(lint, fix);
2030
2034
  } else if (lintc) {
2031
2035
  inquirer.prompt(rules).then(async ({ rule }) => {
2032
- const parentRule =rule;
2036
+ const parentRule = rule;
2033
2037
  if (rule === "currency") {
2034
2038
  const ruleChoice = rules.find((item) => item.name === "rule");
2035
2039
  const currencySubChoice = ruleChoice.choices.find(
@@ -2037,8 +2041,8 @@ if (sass) {
2037
2041
  ).children;
2038
2042
  const { scene } = await inquirer.prompt(currencySubChoice);
2039
2043
  rule = scene;
2040
- if(rule==='customColumnModule'){
2041
- return customColumnModule(lintc,fix,rule,parentRule)
2044
+ if (rule === "customColumnModule") {
2045
+ return customColumnModule(lintc, fix, rule, parentRule);
2042
2046
  }
2043
2047
  }
2044
2048
  lint$1(lintc, fix, rule);
@@ -2161,7 +2165,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2161
2165
  if (isOk) {
2162
2166
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2163
2167
  let key = newAllArr.find(
2164
- (item) => item.path === fPath && item.ZH_CN === p1
2168
+ (item) =>
2169
+ item.path === fPath &&
2170
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2165
2171
  ).key;
2166
2172
  // 去除{ slotxx }
2167
2173
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2204,7 +2210,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2204
2210
  groupArr = allArr;
2205
2211
  }
2206
2212
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2207
- if(!groupArr.length) return
2213
+ if (!groupArr.length) return;
2208
2214
  const task = groupArr.map(async (item, index) => {
2209
2215
  let str = "";
2210
2216
  item.forEach((item1, index1) => {
@@ -2219,11 +2225,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2219
2225
  groupArr.forEach((item, index) => {
2220
2226
  Array.prototype.push.apply(newAllArr, item);
2221
2227
  });
2228
+ // 如果中文不同,但翻译的英文相同(比如商品品类和商品类别翻译的英文都是Product Category),对key进行自动+1
2229
+ for (let i = 0; i < newAllArr.length; i++) {
2230
+ let num = 0;
2231
+ for (let j = 0; j < newAllArr.length; j++) {
2232
+ // key存在且不能为空
2233
+ if (newAllArr[j].key && newAllArr[i].key) {
2234
+ if (
2235
+ newAllArr[j].key === newAllArr[i].key &&
2236
+ newAllArr[j].ZH_CN !== newAllArr[i].ZH_CN
2237
+ ) {
2238
+ num++;
2239
+ newAllArr[j].key = newAllArr[j].key + num;
2240
+ }
2241
+ }
2242
+ }
2243
+ }
2222
2244
  readFolder(true);
2223
-
2245
+ // 如果key相等去重
2246
+ const uniqueArr = Array.from(
2247
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2248
+ );
2224
2249
  let exportData = [];
2225
2250
  // key中有debug排后面
2226
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2251
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2227
2252
  return item.key.indexOf("debug") > -1;
2228
2253
  });
2229
2254
  sortNewAllArr.forEach((item, index) => {
@@ -2288,7 +2313,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2288
2313
  }
2289
2314
  const buffer = xlsx.build([{ data: exportData }]);
2290
2315
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2291
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2316
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2292
2317
  });
2293
2318
  }
2294
2319
 
@@ -2317,9 +2342,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2317
2342
  if (resBody.trans_result) {
2318
2343
  console.log(`ok`);
2319
2344
  let result = resBody.trans_result || [];
2345
+
2320
2346
  item.forEach((item1, index1) => {
2321
2347
  const id = uuid.v5(item1.path, uuid.v5.URL).slice(0, 6);
2322
- if (result[index1] && result[index1].src === item1.ZH_CN) {
2348
+ if (
2349
+ result[index1] &&
2350
+ (result[index1].src === item1.ZH_CN ||
2351
+ result[index1].src === item1.ZH_CN.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2352
+ ) {
2323
2353
  // 删除str中的单引号或双引号或斜杠或逗号
2324
2354
  let str = result[index1].dst
2325
2355
  .replace(/\'/g, "")
@@ -2330,7 +2360,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2330
2360
  const s = str.split(" ");
2331
2361
  let key = s
2332
2362
  .map((item, index) => {
2333
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2363
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2334
2364
  })
2335
2365
  .join("");
2336
2366
  // 去除key中的标点符号
@@ -78,8 +78,9 @@ function importExcel({ uploadFilePath, token, env }) {
78
78
  return new Promise((resolve, reject) => {
79
79
  request(
80
80
  {
81
- url: `https://${env === "pro" ? "" : `${env}-`
82
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
81
+ url: `https://${
82
+ env === "pro" ? "" : `${env}-`
83
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
83
84
  method: "POST",
84
85
  headers: {
85
86
  contentType: "multipart/form-data",
@@ -97,7 +98,9 @@ function importExcel({ uploadFilePath, token, env }) {
97
98
  resolve(true);
98
99
  } else {
99
100
  Loading$1.fail(`${env}: 导入文件失败`);
100
- console.log(chalk.red(error || JSON.stringify(res.data)));
101
+ console.log(
102
+ chalk.red(error || (res.data ? JSON.stringify(res.data) : res.msg))
103
+ );
101
104
  }
102
105
  }
103
106
  );
@@ -143,8 +146,9 @@ function uploadExcel({ data, token, env }) {
143
146
  return new Promise((resolve, reject) => {
144
147
  request(
145
148
  {
146
- url: `https://${env === "pro" ? "" : `${env}-`
147
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
149
+ url: `https://${
150
+ env === "pro" ? "" : `${env}-`
151
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
148
152
  method: "POST",
149
153
  json: true,
150
154
  headers: {
@@ -2007,7 +2011,7 @@ if (sass) {
2007
2011
  lint$1(lint, fix);
2008
2012
  } else if (lintc) {
2009
2013
  inquirer.prompt(rules).then(async ({ rule }) => {
2010
- const parentRule =rule;
2014
+ const parentRule = rule;
2011
2015
  if (rule === "currency") {
2012
2016
  const ruleChoice = rules.find((item) => item.name === "rule");
2013
2017
  const currencySubChoice = ruleChoice.choices.find(
@@ -2015,8 +2019,8 @@ if (sass) {
2015
2019
  ).children;
2016
2020
  const { scene } = await inquirer.prompt(currencySubChoice);
2017
2021
  rule = scene;
2018
- if(rule==='customColumnModule'){
2019
- return customColumnModule(lintc,fix,rule,parentRule)
2022
+ if (rule === "customColumnModule") {
2023
+ return customColumnModule(lintc, fix, rule, parentRule);
2020
2024
  }
2021
2025
  }
2022
2026
  lint$1(lintc, fix, rule);
@@ -2139,7 +2143,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2139
2143
  if (isOk) {
2140
2144
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2141
2145
  let key = newAllArr.find(
2142
- (item) => item.path === fPath && item.ZH_CN === p1
2146
+ (item) =>
2147
+ item.path === fPath &&
2148
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2143
2149
  ).key;
2144
2150
  // 去除{ slotxx }
2145
2151
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2182,7 +2188,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2182
2188
  groupArr = allArr;
2183
2189
  }
2184
2190
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2185
- if(!groupArr.length) return
2191
+ if (!groupArr.length) return;
2186
2192
  const task = groupArr.map(async (item, index) => {
2187
2193
  let str = "";
2188
2194
  item.forEach((item1, index1) => {
@@ -2197,11 +2203,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2197
2203
  groupArr.forEach((item, index) => {
2198
2204
  Array.prototype.push.apply(newAllArr, item);
2199
2205
  });
2206
+ // 如果中文不同,但翻译的英文相同(比如商品品类和商品类别翻译的英文都是Product Category),对key进行自动+1
2207
+ for (let i = 0; i < newAllArr.length; i++) {
2208
+ let num = 0;
2209
+ for (let j = 0; j < newAllArr.length; j++) {
2210
+ // key存在且不能为空
2211
+ if (newAllArr[j].key && newAllArr[i].key) {
2212
+ if (
2213
+ newAllArr[j].key === newAllArr[i].key &&
2214
+ newAllArr[j].ZH_CN !== newAllArr[i].ZH_CN
2215
+ ) {
2216
+ num++;
2217
+ newAllArr[j].key = newAllArr[j].key + num;
2218
+ }
2219
+ }
2220
+ }
2221
+ }
2200
2222
  readFolder(true);
2201
-
2223
+ // 如果key相等去重
2224
+ const uniqueArr = Array.from(
2225
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2226
+ );
2202
2227
  let exportData = [];
2203
2228
  // key中有debug排后面
2204
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2229
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2205
2230
  return item.key.indexOf("debug") > -1;
2206
2231
  });
2207
2232
  sortNewAllArr.forEach((item, index) => {
@@ -2266,7 +2291,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2266
2291
  }
2267
2292
  const buffer = xlsx.build([{ data: exportData }]);
2268
2293
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2269
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2294
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2270
2295
  });
2271
2296
  }
2272
2297
 
@@ -2295,9 +2320,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2295
2320
  if (resBody.trans_result) {
2296
2321
  console.log(`ok`);
2297
2322
  let result = resBody.trans_result || [];
2323
+
2298
2324
  item.forEach((item1, index1) => {
2299
2325
  const id = v5(item1.path, v5.URL).slice(0, 6);
2300
- if (result[index1] && result[index1].src === item1.ZH_CN) {
2326
+ if (
2327
+ result[index1] &&
2328
+ (result[index1].src === item1.ZH_CN ||
2329
+ result[index1].src === item1.ZH_CN.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2330
+ ) {
2301
2331
  // 删除str中的单引号或双引号或斜杠或逗号
2302
2332
  let str = result[index1].dst
2303
2333
  .replace(/\'/g, "")
@@ -2308,7 +2338,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2308
2338
  const s = str.split(" ");
2309
2339
  let key = s
2310
2340
  .map((item, index) => {
2311
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2341
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2312
2342
  })
2313
2343
  .join("");
2314
2344
  // 去除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.9",
4
4
  "description": "i18-fe-automator-beta内测版本,只用于key: ''替换、检测中文规则等",
5
5
  "type": "module",
6
6
  "bin": {