i18-fe-automator-beta 1.0.6 → 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.
@@ -100,9 +100,8 @@ function importExcel({ uploadFilePath, token, env }) {
100
100
  return new Promise((resolve, reject) => {
101
101
  request(
102
102
  {
103
- url: `https://${
104
- env === "pro" ? "" : `${env}-`
105
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
103
+ url: `https://${env === "pro" ? "" : `${env}-`
104
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
106
105
  method: "POST",
107
106
  headers: {
108
107
  contentType: "multipart/form-data",
@@ -134,9 +133,14 @@ function readExcel({ uploadFilePath }) {
134
133
  // 获取第一行
135
134
  const titleList = data[0];
136
135
  // 获取项目所在的列
137
- const projectIndex = titleList.indexOf("项目");
138
- if (projectIndex === -1) {
139
- console.log(chalk.red("请检查文件是否包含项目列"));
136
+ let projectIndex;
137
+ if (titleList.indexOf("项目") > -1) {
138
+ projectIndex = titleList.indexOf("项目");
139
+ } else if (titleList.indexOf("project") > -1) {
140
+ projectIndex = titleList.indexOf("project");
141
+ }
142
+ if (!projectIndex && projectIndex !== 0) {
143
+ console.log(chalk.red("请检查文件是否包含项目/project列"));
140
144
  return;
141
145
  }
142
146
  // 获取数据
@@ -161,9 +165,8 @@ function uploadExcel({ data, token, env }) {
161
165
  return new Promise((resolve, reject) => {
162
166
  request(
163
167
  {
164
- url: `https://${
165
- env === "pro" ? "" : `${env}-`
166
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
168
+ url: `https://${env === "pro" ? "" : `${env}-`
169
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
167
170
  method: "POST",
168
171
  json: true,
169
172
  headers: {
@@ -2026,7 +2029,7 @@ if (sass) {
2026
2029
  lint$1(lint, fix);
2027
2030
  } else if (lintc) {
2028
2031
  inquirer.prompt(rules).then(async ({ rule }) => {
2029
- const parentRule =rule;
2032
+ const parentRule = rule;
2030
2033
  if (rule === "currency") {
2031
2034
  const ruleChoice = rules.find((item) => item.name === "rule");
2032
2035
  const currencySubChoice = ruleChoice.choices.find(
@@ -2034,8 +2037,8 @@ if (sass) {
2034
2037
  ).children;
2035
2038
  const { scene } = await inquirer.prompt(currencySubChoice);
2036
2039
  rule = scene;
2037
- if(rule==='customColumnModule'){
2038
- return customColumnModule(lintc,fix,rule,parentRule)
2040
+ if (rule === "customColumnModule") {
2041
+ return customColumnModule(lintc, fix, rule, parentRule);
2039
2042
  }
2040
2043
  }
2041
2044
  lint$1(lintc, fix, rule);
@@ -2158,7 +2161,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2158
2161
  if (isOk) {
2159
2162
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2160
2163
  let key = newAllArr.find(
2161
- (item) => item.path === fPath && item.ZH_CN === p1
2164
+ (item) =>
2165
+ item.path === fPath &&
2166
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2162
2167
  ).key;
2163
2168
  // 去除{ slotxx }
2164
2169
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2201,7 +2206,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2201
2206
  groupArr = allArr;
2202
2207
  }
2203
2208
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2204
- if(!groupArr.length) return
2209
+ if (!groupArr.length) return;
2205
2210
  const task = groupArr.map(async (item, index) => {
2206
2211
  let str = "";
2207
2212
  item.forEach((item1, index1) => {
@@ -2216,11 +2221,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2216
2221
  groupArr.forEach((item, index) => {
2217
2222
  Array.prototype.push.apply(newAllArr, item);
2218
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
+ }
2219
2240
  readFolder(true);
2220
-
2241
+ // 如果key相等去重
2242
+ const uniqueArr = Array.from(
2243
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2244
+ );
2221
2245
  let exportData = [];
2222
2246
  // key中有debug排后面
2223
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2247
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2224
2248
  return item.key.indexOf("debug") > -1;
2225
2249
  });
2226
2250
  sortNewAllArr.forEach((item, index) => {
@@ -2285,7 +2309,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2285
2309
  }
2286
2310
  const buffer = xlsx.build([{ data: exportData }]);
2287
2311
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2288
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2312
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2289
2313
  });
2290
2314
  }
2291
2315
 
@@ -2314,9 +2338,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2314
2338
  if (resBody.trans_result) {
2315
2339
  console.log(`ok`);
2316
2340
  let result = resBody.trans_result || [];
2341
+
2317
2342
  item.forEach((item1, index1) => {
2318
2343
  const id = uuid.v5(item1.path, uuid.v5.URL).slice(0, 6);
2319
- 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
+ ) {
2320
2349
  // 删除str中的单引号或双引号或斜杠或逗号
2321
2350
  let str = result[index1].dst
2322
2351
  .replace(/\'/g, "")
@@ -2327,7 +2356,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2327
2356
  const s = str.split(" ");
2328
2357
  let key = s
2329
2358
  .map((item, index) => {
2330
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2359
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2331
2360
  })
2332
2361
  .join("");
2333
2362
  // 去除key中的标点符号
@@ -78,9 +78,8 @@ function importExcel({ uploadFilePath, token, env }) {
78
78
  return new Promise((resolve, reject) => {
79
79
  request(
80
80
  {
81
- url: `https://${
82
- env === "pro" ? "" : `${env}-`
83
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
81
+ url: `https://${env === "pro" ? "" : `${env}-`
82
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/importLangExcel`,
84
83
  method: "POST",
85
84
  headers: {
86
85
  contentType: "multipart/form-data",
@@ -112,9 +111,14 @@ function readExcel({ uploadFilePath }) {
112
111
  // 获取第一行
113
112
  const titleList = data[0];
114
113
  // 获取项目所在的列
115
- const projectIndex = titleList.indexOf("项目");
116
- if (projectIndex === -1) {
117
- console.log(chalk.red("请检查文件是否包含项目列"));
114
+ let projectIndex;
115
+ if (titleList.indexOf("项目") > -1) {
116
+ projectIndex = titleList.indexOf("项目");
117
+ } else if (titleList.indexOf("project") > -1) {
118
+ projectIndex = titleList.indexOf("project");
119
+ }
120
+ if (!projectIndex && projectIndex !== 0) {
121
+ console.log(chalk.red("请检查文件是否包含项目/project列"));
118
122
  return;
119
123
  }
120
124
  // 获取数据
@@ -139,9 +143,8 @@ function uploadExcel({ data, token, env }) {
139
143
  return new Promise((resolve, reject) => {
140
144
  request(
141
145
  {
142
- url: `https://${
143
- env === "pro" ? "" : `${env}-`
144
- }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
146
+ url: `https://${env === "pro" ? "" : `${env}-`
147
+ }hxjf.hongxinshop.com/vue-api/api-globalization/api/i18n/uploadI18nLangForFront`,
145
148
  method: "POST",
146
149
  json: true,
147
150
  headers: {
@@ -2004,7 +2007,7 @@ if (sass) {
2004
2007
  lint$1(lint, fix);
2005
2008
  } else if (lintc) {
2006
2009
  inquirer.prompt(rules).then(async ({ rule }) => {
2007
- const parentRule =rule;
2010
+ const parentRule = rule;
2008
2011
  if (rule === "currency") {
2009
2012
  const ruleChoice = rules.find((item) => item.name === "rule");
2010
2013
  const currencySubChoice = ruleChoice.choices.find(
@@ -2012,8 +2015,8 @@ if (sass) {
2012
2015
  ).children;
2013
2016
  const { scene } = await inquirer.prompt(currencySubChoice);
2014
2017
  rule = scene;
2015
- if(rule==='customColumnModule'){
2016
- return customColumnModule(lintc,fix,rule,parentRule)
2018
+ if (rule === "customColumnModule") {
2019
+ return customColumnModule(lintc, fix, rule, parentRule);
2017
2020
  }
2018
2021
  }
2019
2022
  lint$1(lintc, fix, rule);
@@ -2136,7 +2139,9 @@ function translateUtil(appid, key, projectName, isLintFix) {
2136
2139
  if (isOk) {
2137
2140
  const reg1 = /key[\r\n\s]*:[\r\n\s]*('|")[\r\n\s]*('|")/g;
2138
2141
  let key = newAllArr.find(
2139
- (item) => item.path === fPath && item.ZH_CN === p1
2142
+ (item) =>
2143
+ item.path === fPath &&
2144
+ (item.ZH_CN === p1 || item.ZH_CN === p1.trim()) // 去除前后空格,原[ 执行人: ]翻译变成[执行人:]
2140
2145
  ).key;
2141
2146
  // 去除{ slotxx }
2142
2147
  key = key.replace(/\{[\r\n\s]*slot\d[\r\n\s]*\}/g, "");
@@ -2179,7 +2184,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2179
2184
  groupArr = allArr;
2180
2185
  }
2181
2186
  console.log(chalk.green(`共有${groupArr.length}组数据需要翻译`));
2182
- if(!groupArr.length) return
2187
+ if (!groupArr.length) return;
2183
2188
  const task = groupArr.map(async (item, index) => {
2184
2189
  let str = "";
2185
2190
  item.forEach((item1, index1) => {
@@ -2194,11 +2199,30 @@ function translateUtil(appid, key, projectName, isLintFix) {
2194
2199
  groupArr.forEach((item, index) => {
2195
2200
  Array.prototype.push.apply(newAllArr, item);
2196
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
+ }
2197
2218
  readFolder(true);
2198
-
2219
+ // 如果key相等去重
2220
+ const uniqueArr = Array.from(
2221
+ new Map(newAllArr.map((item) => [item.key, item])).values()
2222
+ );
2199
2223
  let exportData = [];
2200
2224
  // key中有debug排后面
2201
- const sortNewAllArr = _.sortBy(newAllArr, function (item) {
2225
+ const sortNewAllArr = _.sortBy(uniqueArr, function (item) {
2202
2226
  return item.key.indexOf("debug") > -1;
2203
2227
  });
2204
2228
  sortNewAllArr.forEach((item, index) => {
@@ -2263,7 +2287,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2263
2287
  }
2264
2288
  const buffer = xlsx.build([{ data: exportData }]);
2265
2289
  fs.writeFileSync(`./export.xlsx`, buffer, "binary");
2266
- console.log(chalk.green(`${isMerge?"合并":"覆盖"}文件成功`));
2290
+ console.log(chalk.green(`${isMerge ? "合并" : "覆盖"}文件成功`));
2267
2291
  });
2268
2292
  }
2269
2293
 
@@ -2292,9 +2316,14 @@ function translateUtil(appid, key, projectName, isLintFix) {
2292
2316
  if (resBody.trans_result) {
2293
2317
  console.log(`ok`);
2294
2318
  let result = resBody.trans_result || [];
2319
+
2295
2320
  item.forEach((item1, index1) => {
2296
2321
  const id = v5(item1.path, v5.URL).slice(0, 6);
2297
- 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
+ ) {
2298
2327
  // 删除str中的单引号或双引号或斜杠或逗号
2299
2328
  let str = result[index1].dst
2300
2329
  .replace(/\'/g, "")
@@ -2305,7 +2334,7 @@ function translateUtil(appid, key, projectName, isLintFix) {
2305
2334
  const s = str.split(" ");
2306
2335
  let key = s
2307
2336
  .map((item, index) => {
2308
- return item?( item[0].toUpperCase() + item.slice(1)):item;
2337
+ return item ? item[0].toUpperCase() + item.slice(1) : item;
2309
2338
  })
2310
2339
  .join("");
2311
2340
  // 去除key中的标点符号
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18-fe-automator-beta",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "i18-fe-automator-beta内测版本,只用于key: ''替换、检测中文规则等",
5
5
  "type": "module",
6
6
  "bin": {