ztxkutils 2.10.66-30 → 2.10.66-32

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 (56) hide show
  1. package/dist/print.js +17 -8
  2. package/package.json +1 -1
  3. package/zti18n-cli/bin/index.js +3 -3
  4. package/zti18n-cli/index.js +23 -23
  5. package/zti18n-cli/src/command/collect.js +353 -353
  6. package/zti18n-cli/src/command/convert.js +17 -17
  7. package/zti18n-cli/src/command/convert2.js +35 -35
  8. package/zti18n-cli/src/command/initFileConf.js +133 -133
  9. package/zti18n-cli/src/command/publish.js +24 -24
  10. package/zti18n-cli/src/conf/BaseConf.js +21 -21
  11. package/zti18n-cli/src/conf/FileConf.js +116 -116
  12. package/zti18n-cli/src/index.js +75 -75
  13. package/zti18n-cli/src/translate/google.js +87 -87
  14. package/zti18n-cli/src/utils/isChinese.js +3 -3
  15. package/zti18n-cli/src/utils/log.js +8 -8
  16. package/zti18n-cli/src/utils/mergeOptions.js +45 -45
  17. package/zti18n-cli/src/utils/reactOptions.js +73 -73
  18. package/zti18n-cli/src/utils/vueOptions.js +69 -69
  19. package/zti18n-core/index.js +1 -1
  20. package/zti18n-core/src/index.js +5 -5
  21. package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +224 -224
  22. package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +64 -64
  23. package/zti18n-core/src/transform/defaultPkMap.js +79 -79
  24. package/zti18n-core/src/transform/transformHtml.js +271 -271
  25. package/zti18n-core/src/transform/transformJs.js +489 -489
  26. package/zti18n-core/src/transform/transformPug.js +272 -272
  27. package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +96 -96
  28. package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +90 -90
  29. package/zti18n-core/src/transform/transformToDi18n.js +22 -22
  30. package/zti18n-core/src/transform/transformTs.js +41 -41
  31. package/zti18n-core/src/transform/transformVue.js +126 -126
  32. package/zti18n-core/src/transform/transformZeroToDi18n.js +105 -105
  33. package/zti18n-core/src/translate/google.js +6 -6
  34. package/zti18n-core/src/utils/constants.js +3 -3
  35. package/zti18n-core/src/utils/getIgnoreLines.js +14 -14
  36. package/zti18n-core/src/utils/isChinese.js +3 -3
  37. package/zti18n-core/src/utils/log.js +8 -8
  38. package/dist/dataModel-1fbaff40.js +0 -24
  39. package/dist/dataModel-6c68c88f.js +0 -26
  40. package/dist/dataModel-914b6226.js +0 -26
  41. package/dist/dataModel-b3629ef3.js +0 -26
  42. package/dist/reqUrl-22b880a4.js +0 -82
  43. package/dist/request-1e442d5d.js +0 -2982
  44. package/dist/request-4c29d6de.js +0 -2977
  45. package/dist/request-80d1ac80.js +0 -2992
  46. package/dist/request-986d7090.js +0 -2923
  47. package/dist/request-c0970aae.js +0 -2917
  48. package/dist/request-d1972b41.js +0 -2992
  49. package/dist/request-d8d72b87.js +0 -2982
  50. package/dist/request-f600ad7a.js +0 -2992
  51. package/dist/tools-16a7fb45.js +0 -2446
  52. package/dist/validate-18e52490.js +0 -249
  53. package/dist/validate-21164759.js +0 -260
  54. package/dist/validate-21b58a69.js +0 -260
  55. package/dist/validate-2de5a28f.js +0 -260
  56. package/dist/validate-ab47ebe9.js +0 -260
@@ -1,116 +1,116 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const BaseConf = require('./BaseConf');
4
- const log = require('../utils/log');
5
-
6
- const cwdPath = process.cwd();
7
-
8
- module.exports = class FileConf extends BaseConf {
9
- constructor(folder) {
10
- super();
11
- this.localesDir = folder;
12
- }
13
-
14
- /**
15
- * 创建一个服务
16
- */
17
- createService() {
18
- log.info('No need to create service in FileConf');
19
- return super.createService();
20
- }
21
-
22
- /**
23
- * 创建一个配置
24
- * @param {string} confName 配置名称
25
- * @param {object} values KV值
26
- * @param {object} refValues 参数备注
27
- * @param {string} key locales标识
28
- */
29
- createConf(confName, values, refValues, key) {
30
- const folder = this.localesDir.startsWith('/')
31
- ? this.localesDir
32
- : path.join(cwdPath, this.localesDir);
33
-
34
- try {
35
- fs.accessSync(folder);
36
- } catch (e) {
37
- fs.mkdirSync(folder);
38
- }
39
-
40
- const configFilePath = path.join(folder, `${key}.json`);
41
- return new Promise((resolve, reject) => {
42
- fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
43
- if (err) {
44
- reject(err);
45
- } else {
46
- resolve(configFilePath);
47
- }
48
- });
49
- });
50
- }
51
-
52
- /**
53
- * 更新一个配置
54
- * @param {string} confName 配置名称
55
- * @param {object} values KV值
56
- * @param {object} refValues 参数备注
57
- * @param {string} key locales标识
58
- */
59
- updateConf(confName, values, refValues, key) {
60
- const configFilePath = path.join(cwdPath, this.localesDir, `${key}.json`);
61
- return new Promise((resolve) => {
62
- fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
63
- if (err) {
64
- resolve({
65
- code: -1,
66
- message: err.message,
67
- });
68
- } else {
69
- resolve({
70
- code: 0,
71
- data: configFilePath,
72
- });
73
- }
74
- });
75
- });
76
- }
77
-
78
- /**
79
- * 获取配置值
80
- * @param {string} _ 配置名称
81
- * @param {string} key key
82
- */
83
- getConf(confName, key) {
84
- const configFilePath = path.join(cwdPath, this.localesDir, `${key}.json`);
85
- return new Promise((resolve, reject) => {
86
- if (fs.existsSync(configFilePath)) {
87
- let data = {};
88
- try {
89
- const content = fs.readFileSync(configFilePath);
90
- data = content.length > 0 ? JSON.parse(content) : {};
91
- resolve({
92
- code: 0,
93
- data: Object.keys(data).map((k) => ({
94
- key: k,
95
- value: data[k],
96
- })),
97
- });
98
- } catch (err) {
99
- reject(
100
- new Error(`请检查 ${configFilePath} 资源文件 JSON 格式是否正确`)
101
- );
102
- }
103
- } else {
104
- reject(new Error(`资源文件 ${configFilePath} 不存在`));
105
- }
106
- });
107
- }
108
-
109
- /**
110
- * 发布指定的配置
111
- */
112
- publishConf() {
113
- log.info('No need to publish in FileConf');
114
- return super.publishConf();
115
- }
116
- };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const BaseConf = require('./BaseConf');
4
+ const log = require('../utils/log');
5
+
6
+ const cwdPath = process.cwd();
7
+
8
+ module.exports = class FileConf extends BaseConf {
9
+ constructor(folder) {
10
+ super();
11
+ this.localesDir = folder;
12
+ }
13
+
14
+ /**
15
+ * 创建一个服务
16
+ */
17
+ createService() {
18
+ log.info('No need to create service in FileConf');
19
+ return super.createService();
20
+ }
21
+
22
+ /**
23
+ * 创建一个配置
24
+ * @param {string} confName 配置名称
25
+ * @param {object} values KV值
26
+ * @param {object} refValues 参数备注
27
+ * @param {string} key locales标识
28
+ */
29
+ createConf(confName, values, refValues, key) {
30
+ const folder = this.localesDir.startsWith('/')
31
+ ? this.localesDir
32
+ : path.join(cwdPath, this.localesDir);
33
+
34
+ try {
35
+ fs.accessSync(folder);
36
+ } catch (e) {
37
+ fs.mkdirSync(folder);
38
+ }
39
+
40
+ const configFilePath = path.join(folder, `${key}.json`);
41
+ return new Promise((resolve, reject) => {
42
+ fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
43
+ if (err) {
44
+ reject(err);
45
+ } else {
46
+ resolve(configFilePath);
47
+ }
48
+ });
49
+ });
50
+ }
51
+
52
+ /**
53
+ * 更新一个配置
54
+ * @param {string} confName 配置名称
55
+ * @param {object} values KV值
56
+ * @param {object} refValues 参数备注
57
+ * @param {string} key locales标识
58
+ */
59
+ updateConf(confName, values, refValues, key) {
60
+ const configFilePath = path.join(cwdPath, this.localesDir, `${key}.json`);
61
+ return new Promise((resolve) => {
62
+ fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
63
+ if (err) {
64
+ resolve({
65
+ code: -1,
66
+ message: err.message,
67
+ });
68
+ } else {
69
+ resolve({
70
+ code: 0,
71
+ data: configFilePath,
72
+ });
73
+ }
74
+ });
75
+ });
76
+ }
77
+
78
+ /**
79
+ * 获取配置值
80
+ * @param {string} _ 配置名称
81
+ * @param {string} key key
82
+ */
83
+ getConf(confName, key) {
84
+ const configFilePath = path.join(cwdPath, this.localesDir, `${key}.json`);
85
+ return new Promise((resolve, reject) => {
86
+ if (fs.existsSync(configFilePath)) {
87
+ let data = {};
88
+ try {
89
+ const content = fs.readFileSync(configFilePath);
90
+ data = content.length > 0 ? JSON.parse(content) : {};
91
+ resolve({
92
+ code: 0,
93
+ data: Object.keys(data).map((k) => ({
94
+ key: k,
95
+ value: data[k],
96
+ })),
97
+ });
98
+ } catch (err) {
99
+ reject(
100
+ new Error(`请检查 ${configFilePath} 资源文件 JSON 格式是否正确`)
101
+ );
102
+ }
103
+ } else {
104
+ reject(new Error(`资源文件 ${configFilePath} 不存在`));
105
+ }
106
+ });
107
+ }
108
+
109
+ /**
110
+ * 发布指定的配置
111
+ */
112
+ publishConf() {
113
+ log.info('No need to publish in FileConf');
114
+ return super.publishConf();
115
+ }
116
+ };
@@ -1,75 +1,75 @@
1
- const program = require('commander');
2
- const convert = require('./command/convert');
3
- const convert2 = require('./command/convert2');
4
- const collect = require('./command/collect');
5
- const publish = require('./command/publish');
6
- const option = require('../../package.json');
7
-
8
- module.exports = program;
9
-
10
- program
11
- .version(option.version)
12
- .option(
13
- '-c, --config <path>',
14
- 'set config path. defaults to ./i18n.config.js'
15
- );
16
-
17
- program
18
- .command('sync')
19
- .alias('s')
20
- .description('pick chinese words and snyc with locale conf')
21
- .option('-p, --publish', 'to publish the synced conf or not, defautl : false')
22
- .action(function (options) {
23
- collect(program.opts(), !!options.publish);
24
- })
25
- .on('--help', function () {
26
- console.log(' Examples:');
27
- console.log();
28
- console.log(' sync without publish:');
29
- console.log(' $ zti18n sync -c ./config/prod.config.js');
30
- console.log(' sync and then publish:');
31
- console.log(' $ zti18n sync -p -c ./config/prod.config.js');
32
- console.log();
33
- });
34
-
35
- program
36
- .command('publish')
37
- .description('publish locale confs')
38
- .action(function () {
39
- publish(program.opts());
40
- })
41
- .on('--help', function () {
42
- console.log(' Examples:');
43
- console.log();
44
- console.log(' $ zti18n publish');
45
- console.log();
46
- });
47
-
48
- // XXX: 不表意,需要改一下
49
- program
50
- .command('convert')
51
- .alias('c')
52
- .description('convert to react-intl-universal')
53
- .action(function () {
54
- convert(program.opts());
55
- })
56
- .on('--help', function () {
57
- console.log(' Examples:');
58
- console.log();
59
- console.log(' $ zti18n convert -c ./config/prod.config.js');
60
- console.log();
61
- });
62
-
63
- program
64
- .command('convert2')
65
- .alias('c2')
66
- .description('convert to intl.t')
67
- .action(function () {
68
- convert2(program.opts());
69
- })
70
- .on('--help', function () {
71
- console.log(' Examples:');
72
- console.log();
73
- console.log(' $ zti18n convert2 -c ./config/prod.config.js');
74
- console.log();
75
- });
1
+ const program = require('commander');
2
+ const convert = require('./command/convert');
3
+ const convert2 = require('./command/convert2');
4
+ const collect = require('./command/collect');
5
+ const publish = require('./command/publish');
6
+ const option = require('../../package.json');
7
+
8
+ module.exports = program;
9
+
10
+ program
11
+ .version(option.version)
12
+ .option(
13
+ '-c, --config <path>',
14
+ 'set config path. defaults to ./i18n.config.js'
15
+ );
16
+
17
+ program
18
+ .command('sync')
19
+ .alias('s')
20
+ .description('pick chinese words and snyc with locale conf')
21
+ .option('-p, --publish', 'to publish the synced conf or not, defautl : false')
22
+ .action(function (options) {
23
+ collect(program.opts(), !!options.publish);
24
+ })
25
+ .on('--help', function () {
26
+ console.log(' Examples:');
27
+ console.log();
28
+ console.log(' sync without publish:');
29
+ console.log(' $ zti18n sync -c ./config/prod.config.js');
30
+ console.log(' sync and then publish:');
31
+ console.log(' $ zti18n sync -p -c ./config/prod.config.js');
32
+ console.log();
33
+ });
34
+
35
+ program
36
+ .command('publish')
37
+ .description('publish locale confs')
38
+ .action(function () {
39
+ publish(program.opts());
40
+ })
41
+ .on('--help', function () {
42
+ console.log(' Examples:');
43
+ console.log();
44
+ console.log(' $ zti18n publish');
45
+ console.log();
46
+ });
47
+
48
+ // XXX: 不表意,需要改一下
49
+ program
50
+ .command('convert')
51
+ .alias('c')
52
+ .description('convert to react-intl-universal')
53
+ .action(function () {
54
+ convert(program.opts());
55
+ })
56
+ .on('--help', function () {
57
+ console.log(' Examples:');
58
+ console.log();
59
+ console.log(' $ zti18n convert -c ./config/prod.config.js');
60
+ console.log();
61
+ });
62
+
63
+ program
64
+ .command('convert2')
65
+ .alias('c2')
66
+ .description('convert to intl.t')
67
+ .action(function () {
68
+ convert2(program.opts());
69
+ })
70
+ .on('--help', function () {
71
+ console.log(' Examples:');
72
+ console.log();
73
+ console.log(' $ zti18n convert2 -c ./config/prod.config.js');
74
+ console.log();
75
+ });
@@ -1,87 +1,87 @@
1
- const crypto = require('crypto');
2
- const https = require('https');
3
- const querystring = require('querystring');
4
-
5
- function MD5(string) {
6
- return crypto.createHash('md5').update(string).digest('hex');
7
- }
8
-
9
- function generateRandomString(length) {
10
- // 定义包含所有可能字符的字符串
11
- const characters =
12
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
13
- let result = '';
14
- const charactersLength = characters.length;
15
- for (let i = 0; i < length; i++) {
16
- // 生成一个0到字符集长度之间的随机索引
17
- const randomIndex = Math.floor(Math.random() * charactersLength);
18
- // 从字符集中取出对应索引的字符添加到结果字符串中
19
- result += characters.charAt(randomIndex);
20
- }
21
- return result;
22
- }
23
-
24
- function translateByGoogle(text, targetLang, appid, privatekey) {
25
- const data = {
26
- appid,
27
- nonce_str: generateRandomString(10),
28
- from: 'zh',
29
- to: targetLang,
30
- text: text,
31
- };
32
- const translateData = {
33
- ...data,
34
- privatekey,
35
- };
36
- const stringA = Object.keys(translateData)
37
- .sort()
38
- .map((key) => `${key}=${translateData[key]}`)
39
- .join('&');
40
- const token = MD5(stringA).toUpperCase();
41
-
42
- const agent = new https.Agent({
43
- rejectUnauthorized: false,
44
- });
45
- const postData = querystring.stringify({
46
- ...data,
47
- token,
48
- });
49
- return new Promise((resolve, reject) => {
50
- const req = https.request(
51
- {
52
- hostname: 'aify.zmd.com.cn',
53
- path: '/TranslateApi/api/transText',
54
- method: 'POST',
55
- agent,
56
- headers: {
57
- 'Content-Type': 'application/x-www-form-urlencoded',
58
- 'Content-Length': Buffer.byteLength(postData),
59
- },
60
- },
61
- (res) => {
62
- let data = [];
63
-
64
- res.on('data', (chunk) => {
65
- data.push(chunk);
66
- });
67
-
68
- res.on('end', () => {
69
- const buffer = Buffer.concat(data);
70
- const json = JSON.parse(buffer.toString());
71
- resolve(json.data);
72
- });
73
- }
74
- );
75
-
76
- req.on('error', (error) => {
77
- console.error(error);
78
- reject(error);
79
- });
80
- // 写入请求数据
81
- req.write(postData);
82
- req.end();
83
- });
84
- }
85
- // translateByGoogle('你好', 'en');
86
-
87
- module.exports = translateByGoogle;
1
+ const crypto = require('crypto');
2
+ const https = require('https');
3
+ const querystring = require('querystring');
4
+
5
+ function MD5(string) {
6
+ return crypto.createHash('md5').update(string).digest('hex');
7
+ }
8
+
9
+ function generateRandomString(length) {
10
+ // 定义包含所有可能字符的字符串
11
+ const characters =
12
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
13
+ let result = '';
14
+ const charactersLength = characters.length;
15
+ for (let i = 0; i < length; i++) {
16
+ // 生成一个0到字符集长度之间的随机索引
17
+ const randomIndex = Math.floor(Math.random() * charactersLength);
18
+ // 从字符集中取出对应索引的字符添加到结果字符串中
19
+ result += characters.charAt(randomIndex);
20
+ }
21
+ return result;
22
+ }
23
+
24
+ function translateByGoogle(text, targetLang, appid, privatekey) {
25
+ const data = {
26
+ appid,
27
+ nonce_str: generateRandomString(10),
28
+ from: 'zh',
29
+ to: targetLang,
30
+ text: text,
31
+ };
32
+ const translateData = {
33
+ ...data,
34
+ privatekey,
35
+ };
36
+ const stringA = Object.keys(translateData)
37
+ .sort()
38
+ .map((key) => `${key}=${translateData[key]}`)
39
+ .join('&');
40
+ const token = MD5(stringA).toUpperCase();
41
+
42
+ const agent = new https.Agent({
43
+ rejectUnauthorized: false,
44
+ });
45
+ const postData = querystring.stringify({
46
+ ...data,
47
+ token,
48
+ });
49
+ return new Promise((resolve, reject) => {
50
+ const req = https.request(
51
+ {
52
+ hostname: 'aify.zmd.com.cn',
53
+ path: '/TranslateApi/api/transText',
54
+ method: 'POST',
55
+ agent,
56
+ headers: {
57
+ 'Content-Type': 'application/x-www-form-urlencoded',
58
+ 'Content-Length': Buffer.byteLength(postData),
59
+ },
60
+ },
61
+ (res) => {
62
+ let data = [];
63
+
64
+ res.on('data', (chunk) => {
65
+ data.push(chunk);
66
+ });
67
+
68
+ res.on('end', () => {
69
+ const buffer = Buffer.concat(data);
70
+ const json = JSON.parse(buffer.toString());
71
+ resolve(json.data);
72
+ });
73
+ }
74
+ );
75
+
76
+ req.on('error', (error) => {
77
+ console.error(error);
78
+ reject(error);
79
+ });
80
+ // 写入请求数据
81
+ req.write(postData);
82
+ req.end();
83
+ });
84
+ }
85
+ // translateByGoogle('你好', 'en');
86
+
87
+ module.exports = translateByGoogle;
@@ -1,3 +1,3 @@
1
- module.exports = function isChinese(text) {
2
- return /[\u4e00-\u9fa5]/.test(text);
3
- };
1
+ module.exports = function isChinese(text) {
2
+ return /[\u4e00-\u9fa5]/.test(text);
3
+ };
@@ -1,8 +1,8 @@
1
- const chalk = require('chalk');
2
-
3
- module.exports = {
4
- info: (msg) => console.log(chalk.cyan(msg)),
5
- warning: (msg) => console.log(chalk.yellow(msg)),
6
- success: (msg) => console.log(chalk.green(msg)),
7
- error: (msg) => console.log(chalk.red(msg)),
8
- };
1
+ const chalk = require('chalk');
2
+
3
+ module.exports = {
4
+ info: (msg) => console.log(chalk.cyan(msg)),
5
+ warning: (msg) => console.log(chalk.yellow(msg)),
6
+ success: (msg) => console.log(chalk.green(msg)),
7
+ error: (msg) => console.log(chalk.red(msg)),
8
+ };
@@ -1,45 +1,45 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const defaultOptions = require('./reactOptions');
4
- const log = require('./log');
5
-
6
- const cwdPath = process.cwd();
7
-
8
- module.exports = function mergeOptions(programOption, programParameter) {
9
- const options = defaultOptions;
10
- const configFileName = programOption.config || 'zti18n.config.js';
11
-
12
- const configFilePath = path.join(cwdPath, configFileName);
13
-
14
- // 读取 zti18n-ast.config.js 中设置的参数,然后并入 options
15
- if (fs.existsSync(configFilePath)) {
16
- let configurationFile = {};
17
- try {
18
- configurationFile = require(configFilePath);
19
- } catch (err) {
20
- log.error(`请检查 ${configFileName} 配置文件是否正确\n`);
21
- }
22
-
23
- Object.assign(options, configurationFile);
24
- } else {
25
- log.error(`配置文件 ${configFileName} 不存在\n`);
26
- }
27
-
28
- if (!Object.keys(programOption).length) {
29
- return options;
30
- }
31
-
32
- // 处理命令行参数
33
- programParameter.forEach((k) => {
34
- const value = programOption[k];
35
- if (value) {
36
- if (k === 'exclude' && typeof value === 'string') {
37
- options[k] = value.split(',');
38
- } else {
39
- options[k] = value;
40
- }
41
- }
42
- });
43
-
44
- return options;
45
- };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const defaultOptions = require('./reactOptions');
4
+ const log = require('./log');
5
+
6
+ const cwdPath = process.cwd();
7
+
8
+ module.exports = function mergeOptions(programOption, programParameter) {
9
+ const options = defaultOptions;
10
+ const configFileName = programOption.config || 'zti18n.config.js';
11
+
12
+ const configFilePath = path.join(cwdPath, configFileName);
13
+
14
+ // 读取 zti18n-ast.config.js 中设置的参数,然后并入 options
15
+ if (fs.existsSync(configFilePath)) {
16
+ let configurationFile = {};
17
+ try {
18
+ configurationFile = require(configFilePath);
19
+ } catch (err) {
20
+ log.error(`请检查 ${configFileName} 配置文件是否正确\n`);
21
+ }
22
+
23
+ Object.assign(options, configurationFile);
24
+ } else {
25
+ log.error(`配置文件 ${configFileName} 不存在\n`);
26
+ }
27
+
28
+ if (!Object.keys(programOption).length) {
29
+ return options;
30
+ }
31
+
32
+ // 处理命令行参数
33
+ programParameter.forEach((k) => {
34
+ const value = programOption[k];
35
+ if (value) {
36
+ if (k === 'exclude' && typeof value === 'string') {
37
+ options[k] = value.split(',');
38
+ } else {
39
+ options[k] = value;
40
+ }
41
+ }
42
+ });
43
+
44
+ return options;
45
+ };