@chaoswise/intl 2.1.0 → 2.1.1

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.
@@ -1,34 +1,34 @@
1
- const { v4: uuidv4 } = require("uuid");
1
+ const { v4: uuidv4 } = require('uuid');
2
2
 
3
- const getConf = require("./conf");
4
- const { targetEntryFiles } = require("./util/getTargetFiles");
5
- const transformAst = require("./util/transformAst");
6
- const log = require("./util/log");
7
- const file = require("./util/file");
8
- const writeNewWordsFile = require("./util/writeNewWordsFile");
9
- const { readWordJson } = require("./util/getWord");
10
- const getGroupName = require("./util/getGroupName");
11
- const getPkgJson = require("./util/getPkgJson");
3
+ const getConf = require('./conf');
4
+ const { targetEntryFiles } = require('./util/getTargetFiles');
5
+ const transformAst = require('./util/transformAst');
6
+ const log = require('./util/log');
7
+ const file = require('./util/file');
8
+ const writeNewWordsFile = require('./util/writeNewWordsFile');
9
+ const { readWordJson } = require('./util/getWord');
10
+ const getGroupName = require('./util/getGroupName');
11
+ const getPkgJson = require('./util/getPkgJson');
12
12
 
13
- const service = require("./service");
13
+ const service = require('./service');
14
14
 
15
15
  async function collect() {
16
- log.info("工程扫描中...");
16
+ log.info('工程扫描中...');
17
17
 
18
18
  const package = getPkgJson();
19
19
  const conf = getConf();
20
20
  const groupName = getGroupName();
21
- const newWordsFileType = conf.newWordsFileType || "excel";
21
+ const newWordsFileType = conf.newWordsFileType || 'excel';
22
22
 
23
23
  // 检查newWordsFileType
24
- if (!["json", "excel"].includes(newWordsFileType)) {
24
+ if (!['json', 'excel'].includes(newWordsFileType)) {
25
25
  log.error(`配置:newWordsFileType 只能为json或者excel`);
26
26
  process.exit(1);
27
27
  }
28
28
 
29
29
  // 读取wordJson
30
30
  if (conf.localWordPath && !readWordJson(conf.localWordPath)) {
31
- log.error("localWordPath配置有误");
31
+ log.error('localWordPath配置有误');
32
32
  process.exit(1);
33
33
  }
34
34
 
@@ -37,19 +37,19 @@ async function collect() {
37
37
 
38
38
  // 遍历文件,并对代码进行ast处理的方法:transformAst(type, files, conf, replaceWords)
39
39
  // 第一次遍历,只收集中文,不传入replaceWords
40
- const info = transformAst("Collect", files, conf);
40
+ const info = transformAst('Collect', files, conf);
41
41
 
42
42
  // 在国际化平台中获取所有已存在中文信息
43
- const res = await service.searchByZh(info.allWords);
43
+ const res = await service.searchByZh(info.allWords, groupName);
44
44
  if (res.code !== 10000) {
45
- log.error("请求数据出错:" + res.msg);
45
+ log.error('请求数据出错:' + res.msg);
46
46
  process.exit(1);
47
47
  }
48
48
  const wordsMap = res.data;
49
49
  // 获取所有语种
50
50
  const languageRes = await service.getLanguage();
51
51
  if (languageRes.code !== 10000) {
52
- log.error("请求数据出错:" + languageRes.msg);
52
+ log.error('请求数据出错:' + languageRes.msg);
53
53
  process.exit(1);
54
54
  }
55
55
  const languages = languageRes.data;
@@ -76,7 +76,7 @@ async function collect() {
76
76
  if (Object.keys(currentCopy).length < languages.length) {
77
77
  newWords[currentDt.key] = {};
78
78
  languages.forEach((dt) => {
79
- newWords[currentDt.key][dt.key] = currentCopy[dt.key] || "待翻译";
79
+ newWords[currentDt.key][dt.key] = currentCopy[dt.key] || '待翻译';
80
80
  });
81
81
  } else {
82
82
  exist[currentDt.key] = currentDt;
@@ -99,7 +99,7 @@ async function collect() {
99
99
  });
100
100
  // 词条不存在
101
101
  if (value.length === 0) {
102
- newWords[key][dt.key] = "待翻译";
102
+ newWords[key][dt.key] = '待翻译';
103
103
  }
104
104
  // {"zh_CN": "你好a","zh_TW": "","en_US": "hello"},{"zh_CN": "你好a","en_US": "hello"}
105
105
  // 处理en_US在这两个数据中翻译相同的情况,比如 {en_US: hello}
@@ -110,11 +110,11 @@ async function collect() {
110
110
  else if (hasValue.length > 1) {
111
111
  newWords[key][
112
112
  dt.key
113
- ] = `该词条在平台中对应多个翻译,请手动确认:${hasValue.join("/")}`;
113
+ ] = `该词条在平台中对应多个翻译,请手动确认:${hasValue.join('/')}`;
114
114
  }
115
115
  // 词条存在但是该语种未翻译,比如zh_TW在上面数据中都未翻译的情况
116
116
  else {
117
- newWords[key][dt.key] = "待翻译";
117
+ newWords[key][dt.key] = '待翻译';
118
118
  }
119
119
  }
120
120
  });
@@ -125,10 +125,10 @@ async function collect() {
125
125
  await service.saveExist({ version: package.version, groupName, exist });
126
126
 
127
127
  // 第二次遍历,传入replaceWords,对代码进行国际化通用API转化,把词条替换成数据库的id,或者脚本临时生成的uuid
128
- transformAst("collect", files, conf, replaceWords);
128
+ transformAst('collect', files, conf, replaceWords);
129
129
 
130
- log.success("★★★ 脚本执行成功 ★★★");
131
- log.info("国际化配置文件: .intlconfig.js,可根据需求自定义修改");
130
+ log.success('★★★ 脚本执行成功 ★★★');
131
+ log.info('国际化配置文件: .intlconfig.js,可根据需求自定义修改');
132
132
  // 本次扫描出新的待翻译词条,写入到newWords中
133
133
  if (Object.keys(newWords).length) {
134
134
  writeNewWordsFile(newWordsFileType, newWords, package.version);
@@ -138,7 +138,7 @@ async function collect() {
138
138
  if (warnLogs.length) {
139
139
  const fileName = `intl.logs.warn.${new Date()
140
140
  .toLocaleString()
141
- .replace(/[\/ ]/g, "_")}.txt`;
141
+ .replace(/[\/ ]/g, '_')}.txt`;
142
142
  file.write(fileName, JSON.stringify(warnLogs, null, 2));
143
143
  log.warn(`存在脚本无法处理的情况,具体查看 ${fileName} 手动处理`);
144
144
  }
@@ -1,9 +1,9 @@
1
- const axios = require("axios");
2
- const getConf = require("../conf");
1
+ const axios = require('axios');
2
+ const getConf = require('../conf');
3
3
 
4
4
  const conf = getConf();
5
5
 
6
- axios.defaults.baseURL = (conf.baseURL || "") + "/api/i18n";
6
+ axios.defaults.baseURL = (conf.baseURL || '') + '/api/i18n';
7
7
 
8
8
  axios.interceptors.response.use(
9
9
  function (response) {
@@ -19,26 +19,26 @@ axios.interceptors.response.use(
19
19
  );
20
20
 
21
21
  // 在国际化平台中获取所有已存在中文信息
22
- exports.searchByZh = (zhs) => {
23
- return axios.post("/content/getContentsByMain", zhs);
22
+ exports.searchByZh = (zhs, groupName) => {
23
+ return axios.post('/content/getContentsByMain?groupName=' + groupName, zhs);
24
24
  };
25
25
 
26
26
  // 查询所有语种
27
27
  exports.getLanguage = () => {
28
- return axios.get("/language/list");
28
+ return axios.get('/language/list');
29
29
  };
30
30
 
31
31
  // 根据词条id获取所有数据库词条信息
32
32
  exports.getJson = (data) => {
33
- return axios.post("/content/downloadContentByKeys", data);
33
+ return axios.post('/content/downloadContentByKeys', data);
34
34
  };
35
35
 
36
36
  // 保存替换的特殊方法
37
37
  exports.saveMethod = (data) => {
38
- return axios.post("/history/method/save", data);
38
+ return axios.post('/history/method/save', data);
39
39
  };
40
40
 
41
41
  // 保存已有词条
42
42
  exports.saveExist = (data) => {
43
- return axios.post("/history/exist/save", data);
43
+ return axios.post('/history/exist/save', data);
44
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaoswise/intl",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "author": "cloudwiser",
5
5
  "description": "intl",
6
6
  "main": "lib/index.js",
@@ -84,5 +84,5 @@
84
84
  "react-dom": "^16.13.1"
85
85
  },
86
86
  "license": "MIT",
87
- "gitHead": "f7289295edebb57f5bd96f7f3df2271ebd3aa3f0"
87
+ "gitHead": "39a7b110a359f24658c1b44af5d8867207a76ce4"
88
88
  }