b28-cli 1.7.1 → 1.7.2

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.
Files changed (74) hide show
  1. package/.babelrc +13 -13
  2. package/README.MD +470 -466
  3. package/TestFile/output/lang/BRPT.json +24 -0
  4. package/TestFile/output/lang/CN.json +24 -0
  5. package/TestFile/output/lang/CS.json +24 -0
  6. package/TestFile/output/lang/DE.json +24 -0
  7. package/TestFile/output/lang/EN.json +24 -0
  8. package/TestFile/output/lang/ES.json +24 -0
  9. package/TestFile/output/lang/FR.json +24 -0
  10. package/TestFile/output/lang/HU.json +24 -0
  11. package/TestFile/output/lang/IT.json +24 -0
  12. package/TestFile/output/lang/KO.json +24 -0
  13. package/TestFile/output/lang/LAES.json +24 -0
  14. package/TestFile/output/lang/NL.json +24 -0
  15. package/TestFile/output/lang/PL.json +24 -0
  16. package/TestFile/output/lang/PT.json +24 -0
  17. package/TestFile/output/lang/RO.json +24 -0
  18. package/TestFile/output/lang/RU.json +24 -0
  19. package/TestFile/output/lang/TR.json +24 -0
  20. package/TestFile/output/lang/UK.json +24 -0
  21. package/TestFile/output/lang/ZH.json +24 -0
  22. package/TestFile/output/lang/brpt/translate.json +23 -0
  23. package/TestFile/output/lang/cn/translate.json +23 -0
  24. package/TestFile/output/lang/cs/translate.json +23 -0
  25. package/TestFile/output/lang/de/translate.json +23 -0
  26. package/TestFile/output/lang/es/translate.json +23 -0
  27. package/TestFile/output/lang/fr/translate.json +23 -0
  28. package/TestFile/output/lang/hu/translate.json +23 -0
  29. package/TestFile/output/lang/it/translate.json +23 -0
  30. package/TestFile/output/lang/ko/translate.json +23 -0
  31. package/TestFile/output/lang/laes/translate.json +23 -0
  32. package/TestFile/output/lang/nl/translate.json +23 -0
  33. package/TestFile/output/lang/pl/translate.json +23 -0
  34. package/TestFile/output/lang/pt/translate.json +23 -0
  35. package/TestFile/output/lang/ro/translate.json +23 -0
  36. package/TestFile/output/lang/ru/translate.json +23 -0
  37. package/TestFile/output/lang/tr/translate.json +23 -0
  38. package/TestFile/output/lang/uk/translate.json +23 -0
  39. package/TestFile/output/lang/zh/translate.json +23 -0
  40. package/TestFile/output/lang.json +25 -0
  41. package/b28n.js +739 -739
  42. package/b28nPigeonhole/11ac_ecos_b28n.js +677 -677
  43. package/b28nPigeonhole/11ac_linux_b28n_async.js +709 -709
  44. package/b28nPigeonhole/4G03_b28n_async.js +708 -708
  45. package/b28nPigeonhole/G5310P_b28n.js +650 -650
  46. package/b28nPigeonhole/es5b28n.js +711 -711
  47. package/b28nPigeonhole/es6b28n.js +857 -857
  48. package/b28nPigeonhole/readMe.md +20 -20
  49. package/b28nPigeonhole//345/276/256/344/274/201/350/267/257/347/224/261b28n.js +916 -916
  50. package/dist/ExtractLangExcel.js +138 -45
  51. package/dist/cmd.js +14 -9
  52. package/dist/excel2json.js +215 -54
  53. package/dist/extract/extract-html.js +2 -2
  54. package/dist/extract/extract-js.js +2 -2
  55. package/dist/extract/extract-regexp.js +2 -2
  56. package/dist/extract/extract-vue.js +9 -9
  57. package/dist/extract/extract.js +4 -4
  58. package/dist/extract/extractRegexp/index.js +6 -6
  59. package/dist/extract/vue/html-parser.js +16 -16
  60. package/dist/extract/vue/util.js +2 -2
  61. package/dist/extract/vue/vue-compiler.js +2 -2
  62. package/dist/extractOrigin/extract.js +2 -2
  63. package/dist/extractOrigin/extract_html_ori.js +2 -2
  64. package/dist/extractOrigin/extract_js_ori.js +2 -2
  65. package/dist/handle.js +57 -7
  66. package/dist/index.js +36 -7
  67. package/dist/mergeExcel.js +407 -0
  68. package/dist/mergeJson.js +423 -2
  69. package/dist/util/config.js +90 -32
  70. package/dist/util/index.js +48 -41
  71. package/index.js +5 -5
  72. package/package.json +63 -62
  73. package/result.txt +53 -53
  74. package/test.js +182 -182
@@ -10,17 +10,19 @@ var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
10
10
 
11
11
  var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
12
12
 
13
- var _langArr;
13
+ var _typeof2 = require("babel-runtime/helpers/typeof");
14
14
 
15
- /**
16
- *
17
- * @param {Array} words
18
- * @param {string} jsonPath
19
- * @param {string} outPath
15
+ var _typeof3 = _interopRequireDefault(_typeof2);
16
+
17
+ /**
18
+ * 主函数
19
+ * @param {Array} words
20
+ * @param {string} jsonPath
21
+ * @param {string} outPath
20
22
  */
21
23
  var ExtractLangExcel = function () {
22
24
  var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(words, jsonPath, outPath) {
23
- var outData, jsonFolders, filePath, dataIndex, curLang, _iterator, _isArray, _i, _ref2, jsonKey;
25
+ var outData, jsonFolders, filePath, dataIndex, curLang, timestamp, allTermsPath, problemTermsPath, _iterator, _isArray, _i, _ref2, jsonKey, langCount, problemTerms, problemData;
24
26
 
25
27
  return _regenerator2.default.wrap(function _callee$(_context) {
26
28
  while (1) {
@@ -28,87 +30,117 @@ var ExtractLangExcel = function () {
28
30
  case 0:
29
31
  outData = [], jsonFolders = [], filePath = "", dataIndex = 1, curLang = "en";
30
32
 
33
+
31
34
  jsonPath = (0, _index.correctPath)(jsonPath);
32
35
  jsonFolders = (0, _index.scanFolder)(jsonPath).items;
33
- outPath = _path2.default.join((0, _index.correctPath)(outPath), "lang" + +(0, _index.getNowFormatDate)() + ".xlsx");
36
+ timestamp = (0, _index.getNowFormatDate)();
37
+ allTermsPath = _path2.default.join((0, _index.correctPath)(outPath), "lang_all_" + timestamp + ".xlsx");
38
+ problemTermsPath = _path2.default.join((0, _index.correctPath)(outPath), "lang_problems_" + timestamp + ".xlsx");
39
+
40
+ // 初始化数据结构 - 每一行的数据存在一个数组中
34
41
 
35
- // 每一行的数据存在一个数组中,二维数组outData是完整的数据,用来最终生成excel文件
36
42
  words.forEach(function (item, index) {
37
43
  outData[index] = [];
38
44
  outData[index].push(item);
39
45
  });
40
46
 
47
+ // 添加标题行
48
+ outData.unshift(["词条"]);
49
+
50
+ // 收集所有语言
41
51
  _iterator = jsonFolders, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();
42
52
 
43
- case 6:
53
+ case 9:
44
54
  if (!_isArray) {
45
- _context.next = 12;
55
+ _context.next = 15;
46
56
  break;
47
57
  }
48
58
 
49
59
  if (!(_i >= _iterator.length)) {
50
- _context.next = 9;
60
+ _context.next = 12;
51
61
  break;
52
62
  }
53
63
 
54
- return _context.abrupt("break", 25);
64
+ return _context.abrupt("break", 28);
55
65
 
56
- case 9:
66
+ case 12:
57
67
  _ref2 = _iterator[_i++];
58
- _context.next = 16;
68
+ _context.next = 19;
59
69
  break;
60
70
 
61
- case 12:
71
+ case 15:
62
72
  _i = _iterator.next();
63
73
 
64
74
  if (!_i.done) {
65
- _context.next = 15;
75
+ _context.next = 18;
66
76
  break;
67
77
  }
68
78
 
69
- return _context.abrupt("break", 25);
79
+ return _context.abrupt("break", 28);
70
80
 
71
- case 15:
81
+ case 18:
72
82
  _ref2 = _i.value;
73
83
 
74
- case 16:
84
+ case 19:
75
85
  jsonKey = _ref2;
76
86
 
77
- curLang = langArr[jsonKey] || "en";
87
+ curLang = langArr[jsonKey] || jsonKey;
78
88
  outData[0].push(curLang);
79
89
  filePath = _path2.default.normalize(jsonPath + "/" + jsonKey + "/translate.json");
80
- _context.next = 22;
90
+ _context.next = 25;
81
91
  return getExcelData(words, outData, filePath, dataIndex);
82
92
 
83
- case 22:
93
+ case 25:
84
94
  dataIndex++;
85
95
 
86
- case 23:
87
- _context.next = 6;
96
+ case 26:
97
+ _context.next = 9;
88
98
  break;
89
99
 
90
- case 25:
91
- _context.prev = 25;
100
+ case 28:
101
+ _context.prev = 28;
92
102
 
93
- outData = Array.from([].concat(new Set(outData))[0]);
94
- (0, _index.writeExcel)(outData, outPath, "lang");
95
- (0, _index.log)("\u4EE3\u7801\u4E2D\u6240\u6709\u8BCD\u6761\u7684\u7FFB\u8BD1\u5DF2\u63D0\u53D6\u5B8C\u6210\uFF0C\u4FDD\u5B58\u5728" + outPath + "\u4E2D", _index.LOG_TYPE.DONE);
96
- _context.next = 35;
103
+ // 1. 生成全部词条Excel
104
+ (0, _index.writeExcel)(outData, allTermsPath, "全部词条");
105
+
106
+ // 2. 检查并生成有问题词条Excel
107
+ langCount = jsonFolders.length;
108
+ problemTerms = checkProblemTerms(outData, words, langCount);
109
+
110
+
111
+ if (problemTerms.length > 0) {
112
+ // 构建有问题词条的Excel数据
113
+ problemData = [["词条", "问题原因"].concat(outData[0].slice(1)) // 标题行
114
+ ];
115
+
116
+
117
+ problemTerms.forEach(function (item) {
118
+ problemData.push([item.term, item.problem].concat(item.data.slice(1)));
119
+ });
120
+
121
+ (0, _index.writeExcel)(problemData, problemTermsPath, "有问题词条");
122
+ (0, _index.log)("\u53D1\u73B0" + problemTerms.length + "\u4E2A\u6709\u95EE\u9898\u8BCD\u6761\uFF0C\u5DF2\u4FDD\u5B58\u5728" + problemTermsPath + "\u4E2D", _index.LOG_TYPE.WARNING);
123
+ } else {
124
+ (0, _index.log)("\u6CA1\u6709\u53D1\u73B0\u6709\u95EE\u9898\u8BCD\u6761", _index.LOG_TYPE.INFO);
125
+ }
126
+
127
+ (0, _index.log)("\u8BCD\u6761\u7FFB\u8BD1\u63D0\u53D6\u5B8C\u6210\uFF0C\u5168\u90E8\u8BCD\u6761\u4FDD\u5B58\u5728" + allTermsPath + "\u4E2D", _index.LOG_TYPE.DONE);
128
+ _context.next = 40;
97
129
  break;
98
130
 
99
- case 31:
100
- _context.prev = 31;
101
- _context.t0 = _context["catch"](25);
131
+ case 36:
132
+ _context.prev = 36;
133
+ _context.t0 = _context["catch"](28);
102
134
 
103
135
  (0, _index.log)("\u5199\u5165excel\u5931\u8D25\uFF0C" + _context.t0, _index.LOG_TYPE.ERROR);
104
136
  return _context.abrupt("return", {});
105
137
 
106
- case 35:
138
+ case 40:
107
139
  case "end":
108
140
  return _context.stop();
109
141
  }
110
142
  }
111
- }, _callee, this, [[25, 31]]);
143
+ }, _callee, this, [[28, 36]]);
112
144
  }));
113
145
 
114
146
  return function ExtractLangExcel(_x, _x2, _x3) {
@@ -116,6 +148,9 @@ var ExtractLangExcel = function () {
116
148
  };
117
149
  }();
118
150
 
151
+ // 其余函数保持不变...
152
+
153
+
119
154
  var _path = require("path");
120
155
 
121
156
  var _path2 = _interopRequireDefault(_path);
@@ -124,21 +159,78 @@ var _index = require("./util/index");
124
159
 
125
160
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
126
161
 
127
- var langArr = (_langArr = {
162
+ var langArr = {
128
163
  en: "英语",
129
164
  cn: "简体中文",
130
- zh: "繁體中文",
131
- de: "德语" }, _langArr["en"] = "英语", _langArr.es = "西班牙", _langArr.fr = "法国", _langArr.hu = "匈牙利", _langArr.it = "意大利", _langArr.pl = "波兰", _langArr.ro = "罗马尼亚", _langArr.sa = "阿拉伯", _langArr.tr = "土耳其", _langArr.ru = "俄语", _langArr.pt = "葡萄牙语", _langArr.uk = "乌克兰", _langArr.br = "巴西葡语", _langArr.nl = "荷兰语", _langArr.cs = "捷克语", _langArr.mx = "拉美西语", _langArr.kk = "哈萨克语", _langArr.ko = "韩语", _langArr.bg = "保加利亚语", _langArr.laes = "美西", _langArr.brpt = "巴葡", _langArr);
132
-
133
- function getExcelData(words, outData, filePath, dataIndex) {
165
+ zh: "台湾繁体",
166
+ de: "德语",
167
+ es: "欧洲西语",
168
+ fr: "法语",
169
+ hu: "匈牙利语",
170
+ it: "意大利语",
171
+ pl: "波兰语",
172
+ ro: "罗马尼亚语",
173
+ sa: "阿拉伯语",
174
+ tr: "土耳其语",
175
+ ru: "俄语",
176
+ pt: "葡萄牙语",
177
+ uk: "乌克兰语",
178
+ br: "巴西葡语",
179
+ nl: "荷兰语",
180
+ cs: "捷克语",
181
+ mx: "拉美西语",
182
+ kk: "哈萨克语",
183
+ ko: "韩语",
184
+ bg: "保加利亚语",
185
+ laes: "美西",
186
+ brpt: "巴葡"
187
+ };
188
+
189
+ /**
190
+ * 检查词条是否有问题的函数
191
+ * @param {Array} outData 全部数据
192
+ * @param {Array} words 词条列表
193
+ * @param {number} langCount 语言数量
194
+ * @returns {Array} 有问题的词条数据
195
+ */
196
+ function checkProblemTerms(outData, words, langCount) {
197
+ var problemTerms = [];
198
+
199
+ // 跳过标题行(第一行)
200
+ for (var i = 1; i < outData.length; i++) {
201
+ var row = outData[i];
202
+ var term = words[i - 1]; // 对应原始词条
203
+ var hasProblem = false;
204
+ var problemReason = "";
205
+
206
+ // 检查每一行是否有空值(从第2列开始,第1列是词条本身)
207
+ for (var j = 1; j <= langCount; j++) {
208
+ var cell = row[j];
209
+ if (!cell || (typeof cell === "undefined" ? "undefined" : (0, _typeof3.default)(cell)) === 'object' && !cell.v) {
210
+ hasProblem = true;
211
+ problemReason = "缺失翻译";
212
+ break;
213
+ }
214
+ }
215
+
216
+ // 如果发现问题,添加到问题列表
217
+ if (hasProblem) {
218
+ problemTerms.push({
219
+ term: term,
220
+ problem: problemReason,
221
+ data: row
222
+ });
223
+ }
224
+ }
225
+
226
+ return problemTerms;
227
+ }function getExcelData(words, outData, filePath, dataIndex) {
134
228
  return (0, _index.loadJson)(filePath).then(function (data) {
135
229
  data = trimJson(data);
136
- // data是json文件的值,json对象
137
230
  words.forEach(function (item, wordIndex) {
138
231
  item = trimStr(item);
139
- if (wordIndex == "0") {
140
- return true;
141
- }
232
+ if (wordIndex === 0) return; // 跳过标题行
233
+
142
234
  if (data[item]) {
143
235
  outData[wordIndex][dataIndex] = data[item];
144
236
  } else {
@@ -173,4 +265,5 @@ function trimStr(str) {
173
265
  unescape(str);
174
266
  return str;
175
267
  }
268
+
176
269
  exports.default = ExtractLangExcel;
package/dist/cmd.js CHANGED
@@ -21,18 +21,18 @@ var _fs2 = _interopRequireDefault(_fs);
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
 
23
23
  // 处理一些简单的命令
24
- /**
25
- * b28-cli init
26
- * b28-cli -v/v
27
- * b28-cli -h/h
24
+ /**
25
+ * b28-cli init
26
+ * b28-cli -v/v
27
+ * b28-cli -h/h
28
28
  */
29
29
  var inquirer = require("inquirer");
30
30
 
31
31
  var figlet = require("figlet");
32
32
 
33
33
 
34
- /**
35
- * 生成配置文件需要的注释
34
+ /**
35
+ * 生成配置文件需要的注释
36
36
  */
37
37
  var comments = {
38
38
  commandType: "操作类型",
@@ -65,11 +65,16 @@ var comments = {
65
65
  inExcel: "最终的语言包excel文件地址",
66
66
  transFilePath: "待转码文件地址",
67
67
  transOutPath: "转码后文件输出地址",
68
- transEncode: "转码后文件的编码方式(默认UTF-8)"
68
+ transEncode: "转码后文件的编码方式(默认UTF-8)",
69
+ excelPath1: "第一个Excel文件地址",
70
+ excelPath2: "第二个Excel文件地址",
71
+ sheetName1: "第一个Excel中对应的sheet",
72
+ sheetName2: "第二个Excel中对应的sheet",
73
+ outPath: "输出json文件目录"
69
74
  };
70
75
 
71
- /**
72
- * 初始化b28.config.js文件
76
+ /**
77
+ * 初始化b28.config.js文件
73
78
  */
74
79
  function handleInit() {
75
80
  var config = {};
@@ -2,75 +2,227 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
 
5
+ var _regenerator = require("babel-runtime/regenerator");
6
+
7
+ var _regenerator2 = _interopRequireDefault(_regenerator);
8
+
9
+ var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
10
+
11
+ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
12
+
13
+ /**
14
+ * excelPath, outPath, sheetName, key, value
15
+ */
16
+ var excel2json = function () {
17
+ var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(option) {
18
+ var data, outPath, promiseList, key, langDirName, langDirPath, _outPath;
19
+
20
+ return _regenerator2.default.wrap(function _callee$(_context) {
21
+ while (1) {
22
+ switch (_context.prev = _context.next) {
23
+ case 0:
24
+ option.saveData = option.saveData === false ? false : true;
25
+ data = (0, _index.loadExcel)(option.excelPath, option.sheetName);
26
+
27
+
28
+ if (option.key) {
29
+ option.key = option.key.toUpperCase();
30
+ }
31
+ if (option.value) {
32
+ option.value = option.value.toUpperCase();
33
+ }
34
+
35
+ if (!(data.length === 0)) {
36
+ _context.next = 7;
37
+ break;
38
+ }
39
+
40
+ (0, _index.log)("\u6570\u636E\u4E3A\u7A7A\uFF0C\u53EF\u80FD\u662Fsheetname\u4E0D\u5B58\u5728\u5BFC\u81F4\u7684", _index.LOG_TYPE.WARNING);
41
+ return _context.abrupt("return", Promise.resolve([]));
42
+
43
+ case 7:
44
+ data = transferData(data, option);
45
+
46
+ if (!(data === -1)) {
47
+ _context.next = 10;
48
+ break;
49
+ }
50
+
51
+ return _context.abrupt("return", Promise.resolve({}));
52
+
53
+ case 10:
54
+ if (!option.outPath) {
55
+ _context.next = 37;
56
+ break;
57
+ }
58
+
59
+ if (!Array.isArray(data)) {
60
+ _context.next = 16;
61
+ break;
62
+ }
63
+
64
+ outPath = _path2.default.join(option.outPath, option.fileName || "lang.json");
65
+ return _context.abrupt("return", (0, _index.writeJson)(data, outPath).then(function (data) {
66
+ (0, _index.log)("Excel to Json\u6587\u4EF6\u5DF2\u5199\u5165\u5730\u5740-" + outPath);
67
+ return data;
68
+ }).catch(function (error) {
69
+ (0, _index.log)("Excel to Json\u5931\u8D25\uFF0C" + error, _index.LOG_TYPE.ERROR);
70
+ return {};
71
+ }));
72
+
73
+ case 16:
74
+ promiseList = [];
75
+
76
+ option.outPath = _path2.default.join(option.outPath, "lang");
77
+
78
+ // 确保lang目录存在
79
+ _context.next = 20;
80
+ return _fsExtra2.default.ensureDir(option.outPath);
81
+
82
+ case 20:
83
+ _context.t0 = _regenerator2.default.keys(data);
84
+
85
+ case 21:
86
+ if ((_context.t1 = _context.t0()).done) {
87
+ _context.next = 34;
88
+ break;
89
+ }
90
+
91
+ key = _context.t1.value;
92
+
93
+ // 使用配置的语种简写作为目录名(与 mergeExcel / ExtractLangExcel 保持一致)
94
+ langDirName = getLangDirName(key);
95
+ // 未配置简写时跳过该列,避免生成与配置不一致的目录名
96
+
97
+ if (langDirName) {
98
+ _context.next = 27;
99
+ break;
100
+ }
101
+
102
+ (0, _index.log)("\u672A\u5728\u8BED\u79CD\u6620\u5C04\u8868\u4E2D\u627E\u5230\u7B80\u5199\u914D\u7F6E\uFF0C\u5DF2\u8DF3\u8FC7\u5217\uFF1A" + key, _index.LOG_TYPE.WARNING);
103
+ return _context.abrupt("continue", 21);
104
+
105
+ case 27:
106
+ langDirPath = _path2.default.join(option.outPath, langDirName);
107
+ _context.next = 30;
108
+ return _fsExtra2.default.ensureDir(langDirPath);
109
+
110
+ case 30:
111
+
112
+ // 固定文件名为 translate.json
113
+ _outPath = _path2.default.join(langDirPath, "translate.json");
114
+
115
+ promiseList.push((0, _index.writeJson)(data[key], _outPath));
116
+ _context.next = 21;
117
+ break;
118
+
119
+ case 34:
120
+ return _context.abrupt("return", Promise.all(promiseList).then(function (data1) {
121
+ (0, _index.log)("Excel to Json\u6587\u4EF6\u5DF2\u5199\u5165\u6587\u4EF6\u5939-" + option.outPath + "\u4E0B");
122
+ return data;
123
+ }).catch(function (error) {
124
+ (0, _index.log)("Excel to Json\u5931\u8D25\uFF0C" + error, _index.LOG_TYPE.ERROR);
125
+ return {};
126
+ }));
127
+
128
+ case 35:
129
+ _context.next = 39;
130
+ break;
131
+
132
+ case 37:
133
+ (0, _index.log)("Excel to Json\u6210\u529F\uFF0C\u65E0\u9700\u4FDD\u5B58\u5230\u672C\u5730");
134
+ return _context.abrupt("return", Promise.resolve(data));
135
+
136
+ case 39:
137
+ case "end":
138
+ return _context.stop();
139
+ }
140
+ }
141
+ }, _callee, this);
142
+ }));
143
+
144
+ return function excel2json(_x) {
145
+ return _ref.apply(this, arguments);
146
+ };
147
+ }();
148
+
149
+ /**
150
+ * 提供value输出对象json, 不提供输出数组json
151
+ * value为值对应的语言列,多个语言列用逗号隔开
152
+ */
153
+
154
+
5
155
  var _index = require("./util/index");
6
156
 
7
157
  var _path = require("path");
8
158
 
9
159
  var _path2 = _interopRequireDefault(_path);
10
160
 
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
161
+ var _fsExtra = require("fs-extra");
12
162
 
13
- /**
14
- * excelPath, outPath, sheetName, key, value
15
- */
16
- function excel2json(option) {
17
- option.saveData = option.saveData === false ? false : true;
18
- var data = (0, _index.loadExcel)(option.excelPath, option.sheetName);
163
+ var _fsExtra2 = _interopRequireDefault(_fsExtra);
19
164
 
20
- if (option.key) {
21
- option.key = option.key.toUpperCase();
22
- }
23
- if (option.value) {
24
- option.value = option.value.toUpperCase();
25
- }
26
- if (data.length === 0) {
27
- (0, _index.log)("\u6570\u636E\u4E3A\u7A7A\uFF0C\u53EF\u80FD\u662Fsheetname\u4E0D\u5B58\u5728\u5BFC\u81F4\u7684", _index.LOG_TYPE.WARNING);
28
- return Promise.resolve([]);
29
- }
30
- data = transferData(data, option);
165
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
166
 
32
- if (data === -1) {
33
- return Promise.resolve({});
167
+ // 语种映射表,与 mergeExcel.js / ExtractLangExcel.js 中的 langArr 保持一致
168
+ // key 为语种简写(用于输出文件夹名),value 为对应中文描述,仅用于展示
169
+ var langArr = {
170
+ en: "英语",
171
+ cn: "简体中文",
172
+ zh: "台湾繁体",
173
+ de: "德语",
174
+ es: "欧洲西语",
175
+ fr: "法语",
176
+ hu: "匈牙利语",
177
+ it: "意大利语",
178
+ pl: "波兰语",
179
+ ro: "罗马尼亚语",
180
+ sa: "阿拉伯语",
181
+ tr: "土耳其语",
182
+ ru: "俄语",
183
+ pt: "葡萄牙语",
184
+ uk: "乌克兰语",
185
+ br: "巴西葡语",
186
+ nl: "荷兰语",
187
+ cs: "捷克语",
188
+ mx: "拉美西语",
189
+ kk: "哈萨克语",
190
+ ko: "韩语",
191
+ bg: "保加利亚语",
192
+ laes: "美西",
193
+ brpt: "巴葡"
194
+ };
195
+
196
+ /**
197
+ * 根据语种名称或列名找到对应的语种简写(用于输出目录名)
198
+ * 规则:
199
+ * 1. 先按去空格+小写在 langArr 的 key 中查找
200
+ * 2. 再按值匹配 langArr 的中文描述
201
+ * 3. 都找不到则返回空字符串(表示未配置,不再自动生成新简写)
202
+ */
203
+ function getLangDirName(langName) {
204
+ if (!langName || typeof langName !== "string") {
205
+ return "";
34
206
  }
35
207
 
36
- if (option.outPath) {
37
- if (Array.isArray(data)) {
38
- var outPath = _path2.default.join(option.outPath, option.fileName || "lang.json");
208
+ // 去掉空格并转为小写
209
+ var normalized = langName.replace(/\s+/g, "").toLowerCase();
39
210
 
40
- return (0, _index.writeJson)(data, outPath).then(function (data) {
41
- (0, _index.log)("Excel to Json\u6587\u4EF6\u5DF2\u5199\u5165\u5730\u5740-" + outPath);
42
- return data;
43
- }).catch(function (error) {
44
- (0, _index.log)("Excel to Json\u5931\u8D25\uFF0C" + error, _index.LOG_TYPE.ERROR);
45
- return {};
46
- });
47
- } else {
48
- var promiseList = [];
49
- option.outPath = _path2.default.join(option.outPath, "lang");
50
- for (var key in data) {
51
- var _outPath = _path2.default.join(option.outPath, key + ".json");
211
+ // 直接使用配置的简写(langArr key)
212
+ if (langArr[normalized]) {
213
+ return normalized;
214
+ }
52
215
 
53
- promiseList.push((0, _index.writeJson)(data[key], _outPath));
54
- }
55
- return Promise.all(promiseList).then(function (data1) {
56
- (0, _index.log)("Excel to Json\u6587\u4EF6\u5DF2\u5199\u5165\u6587\u4EF6\u5939-" + option.outPath + "\u4E0B");
57
- return data;
58
- }).catch(function (error) {
59
- (0, _index.log)("Excel to Json\u5931\u8D25\uFF0C" + error, _index.LOG_TYPE.ERROR);
60
- return {};
61
- });
216
+ // 按中文描述反向匹配
217
+ for (var key in langArr) {
218
+ if (langArr[key] === langName || langArr[key].toLowerCase() === normalized) {
219
+ return key;
62
220
  }
63
- } else {
64
- (0, _index.log)("Excel to Json\u6210\u529F\uFF0C\u65E0\u9700\u4FDD\u5B58\u5230\u672C\u5730");
65
- return Promise.resolve(data);
66
221
  }
67
- }
68
222
 
69
- /**
70
- * 提供value输出对象json, 不提供输出数组json
71
- * value为值对应的语言列,多个语言列用逗号隔开
72
- */
73
- function transferData(data, option) {
223
+ // 未在配置表中找到,返回空串,后续逻辑可据此判断是否跳过该语种
224
+ return "";
225
+ }function transferData(data, option) {
74
226
  var keyValueRow = data.shift(),
75
227
  key = option.key,
76
228
  value = option.value || "",
@@ -98,7 +250,10 @@ function transferData(data, option) {
98
250
  }
99
251
  outData.push(value);
100
252
  });
101
- return outData;
253
+ // 过滤掉 undefined 和空字符串
254
+ return outData.filter(function (v) {
255
+ return v !== undefined && v !== "";
256
+ });
102
257
  }
103
258
 
104
259
  // 多列解析,同时对重复的词条进行重新编码
@@ -174,6 +329,12 @@ function transferData(data, option) {
174
329
  transData[keyWorld] = valueWorld;
175
330
  });
176
331
  }
332
+ // 过滤掉 key 为 undefined 或 "" 的项
333
+ Object.keys(transData).forEach(function (k) {
334
+ if (k === undefined || k === "") {
335
+ delete transData[k];
336
+ }
337
+ });
177
338
  outData[valItem] = transData;
178
339
  });
179
340
 
@@ -39,8 +39,8 @@ var Edit_TYPE = {
39
39
  title: 5
40
40
  };
41
41
 
42
- /**
43
- * HTML文件解析类
42
+ /**
43
+ * HTML文件解析类
44
44
  */
45
45
 
46
46
  var ExtractHTML = function (_Extract) {
@@ -39,8 +39,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
39
39
  var parseType = /^(CallExpression|StringLiteral|TemplateLiteral)$/i;
40
40
  var inTranslate = false;
41
41
 
42
- /**
43
- * JS文件解析类
42
+ /**
43
+ * JS文件解析类
44
44
  */
45
45
 
46
46
  var ExtractJs = function (_Extract) {
@@ -24,8 +24,8 @@ var _extractRegexp2 = _interopRequireDefault(_extractRegexp);
24
24
 
25
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
26
 
27
- /**
28
- * 通过正则匹配对词条进行提取
27
+ /**
28
+ * 通过正则匹配对词条进行提取
29
29
  */
30
30
  var ExtractOld = function (_Extract) {
31
31
  (0, _inherits3.default)(ExtractOld, _Extract);