ztxkutils 2.10.66-13-beta → 2.10.66-14
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.
- package/package.json +17 -16
- package/zti18n-cli/bin/index.js +1 -1
- package/zti18n-cli/index.js +1 -1
- package/zti18n-cli/src/command/initFileConf.js +13 -15
- package/zti18n-cli/src/command/publish.js +1 -1
- package/zti18n-cli/src/conf/FileConf.js +10 -10
- package/zti18n-cli/src/index.js +6 -6
- package/zti18n-cli/src/utils/log.js +4 -4
- package/zti18n-cli/src/utils/mergeOptions.js +3 -3
- package/zti18n-cli/src/utils/reactOptions.js +0 -1
- package/zti18n-cli/src/utils/vueOptions.js +0 -1
- package/zti18n-core/src/plugin/reactIntlToReactIntlUniversal.js +19 -19
- package/zti18n-core/src/plugin/reactIntlUniversalToDi18n.js +9 -4
- package/zti18n-core/src/transform/defaultPkMap.js +75 -75
- package/zti18n-core/src/transform/transformHtml.js +31 -35
- package/zti18n-core/src/transform/transformJs.js +49 -63
- package/zti18n-core/src/transform/transformPug.js +59 -49
- package/zti18n-core/src/transform/transformReactIntlToReactIntlUniversal.js +2 -2
- package/zti18n-core/src/transform/transformReactIntlUniveralToDi18n.js +2 -2
- package/zti18n-core/src/transform/transformTs.js +1 -5
- package/zti18n-core/src/transform/transformVue.js +7 -7
- package/zti18n-core/src/utils/log.js +4 -4
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ztxkutils",
|
3
|
-
"version": "2.10.66-
|
3
|
+
"version": "2.10.66-14",
|
4
4
|
"description": "",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -52,17 +52,6 @@
|
|
52
52
|
"ztxkui": "^0.4.1"
|
53
53
|
},
|
54
54
|
"dependencies": {
|
55
|
-
"crypto-js": "^4.1.1",
|
56
|
-
"decimal.js-light": "^2.5.1",
|
57
|
-
"dexie": "^3.2.3",
|
58
|
-
"i18next": "^23.16.4",
|
59
|
-
"js-base64": "^3.6.0",
|
60
|
-
"jwt-decode": "^3.1.2",
|
61
|
-
"screenfull": "^5.1.0",
|
62
|
-
"sockjs-client": "^1.5.1",
|
63
|
-
"stompjs": "^2.3.3",
|
64
|
-
"zt-sockjs-client": "^0.0.2",
|
65
|
-
"zt-stompjs": "^1.1.2",
|
66
55
|
"@babel/core": "^7.18.10",
|
67
56
|
"@babel/generator": "^7.18.0",
|
68
57
|
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
|
@@ -82,17 +71,29 @@
|
|
82
71
|
"@prettier/plugin-pug": "^1.8.1",
|
83
72
|
"@typescript-eslint/typescript-estree": "^3.8.0",
|
84
73
|
"@vitalets/google-translate-api": "^8.0.0",
|
74
|
+
"babel-template": "^6.26.0",
|
85
75
|
"chalk": "^3.0.0",
|
76
|
+
"commander": "^2.18.0",
|
77
|
+
"crypto-js": "^4.1.1",
|
78
|
+
"decimal.js-light": "^2.5.1",
|
79
|
+
"dexie": "^3.2.3",
|
80
|
+
"di18n-core": "^0.1.29",
|
86
81
|
"glob": "^7.1.6",
|
82
|
+
"i18next": "^23.16.4",
|
83
|
+
"inquirer": "^6.2.2",
|
84
|
+
"js-base64": "^3.6.0",
|
85
|
+
"jwt-decode": "^3.1.2",
|
87
86
|
"mustache": "^4.0.1",
|
88
87
|
"parse5": "^5.1.1",
|
89
88
|
"pug-lexer": "^4.1.0",
|
90
89
|
"pug-parser": "^5.0.1",
|
91
90
|
"pug-source-gen": "0.0.2",
|
92
|
-
"
|
93
|
-
"
|
94
|
-
"
|
95
|
-
"
|
91
|
+
"screenfull": "^5.1.0",
|
92
|
+
"sockjs-client": "^1.5.1",
|
93
|
+
"stompjs": "^2.3.3",
|
94
|
+
"vue-template-compiler": "^2.7.16",
|
95
|
+
"zt-sockjs-client": "^0.0.2",
|
96
|
+
"zt-stompjs": "^1.1.2"
|
96
97
|
},
|
97
98
|
"peerDependencies": {
|
98
99
|
"axios": ">=0.21.1",
|
package/zti18n-cli/bin/index.js
CHANGED
package/zti18n-cli/index.js
CHANGED
@@ -10,7 +10,7 @@ const log = require('../utils/log');
|
|
10
10
|
|
11
11
|
function getLocaleFiles({ path, exclude }) {
|
12
12
|
return glob.sync(`${path}/**/*.json`, {
|
13
|
-
ignore: (exclude || []).map(e => `${path}/${e}`),
|
13
|
+
ignore: (exclude || []).map((e) => `${path}/${e}`),
|
14
14
|
});
|
15
15
|
}
|
16
16
|
|
@@ -18,7 +18,7 @@ async function doInquire() {
|
|
18
18
|
// 1. whether overwrite?
|
19
19
|
let configExist = true;
|
20
20
|
try {
|
21
|
-
fs.accessSync('./
|
21
|
+
fs.accessSync('./zti18n.config.js');
|
22
22
|
} catch (e) {
|
23
23
|
configExist = false;
|
24
24
|
}
|
@@ -28,7 +28,7 @@ async function doInquire() {
|
|
28
28
|
{
|
29
29
|
name: 'overwrite',
|
30
30
|
type: 'confirm',
|
31
|
-
message: '配置文件
|
31
|
+
message: '配置文件 zti18n.config.js 已存在,是否覆盖?',
|
32
32
|
},
|
33
33
|
]);
|
34
34
|
|
@@ -67,14 +67,12 @@ module.exports = async function initFileConf(isVue) {
|
|
67
67
|
|
68
68
|
// 配置信息写入文件
|
69
69
|
fs.writeFileSync(
|
70
|
-
'./
|
71
|
-
prettier.format(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
),
|
70
|
+
'./zti18n.config.js',
|
71
|
+
prettier.format('module.exports = ' + JSON.stringify(options), {
|
72
|
+
parser: 'babel',
|
73
|
+
singleQuote: true,
|
74
|
+
trailingComma: 'es5',
|
75
|
+
}),
|
78
76
|
'utf8'
|
79
77
|
);
|
80
78
|
|
@@ -86,7 +84,7 @@ module.exports = async function initFileConf(isVue) {
|
|
86
84
|
const locales = getLocaleFiles({ path: localePath });
|
87
85
|
|
88
86
|
// 读取国际化资源
|
89
|
-
const data = locales.map(element => {
|
87
|
+
const data = locales.map((element) => {
|
90
88
|
// TODO: 支持国际化资源为 js 文件的情况,目前只支持为 json 文件。
|
91
89
|
const json = fs.readFileSync(element, {
|
92
90
|
encoding: 'utf-8',
|
@@ -105,13 +103,13 @@ module.exports = async function initFileConf(isVue) {
|
|
105
103
|
createTasks = data.map(({ confName, value, key }) => {
|
106
104
|
let commentValue = {};
|
107
105
|
if (key !== options.primaryLocale) {
|
108
|
-
commentValue = data.find(d => d.key === options.primaryLocale).value;
|
106
|
+
commentValue = data.find((d) => d.key === options.primaryLocale).value;
|
109
107
|
}
|
110
108
|
return confService.createConf(confName, value, commentValue, key);
|
111
109
|
});
|
112
110
|
} else {
|
113
111
|
// 首次国际化,只需要创建配置
|
114
|
-
createTasks = options.supportedLocales.map(key => {
|
112
|
+
createTasks = options.supportedLocales.map((key) => {
|
115
113
|
const value = { TBD: 'TBD' }; // 创建配置时,必须要有一个 k/V
|
116
114
|
const confName = key; // 初始化时,先创建测试环境的配置
|
117
115
|
return confService.createConf(confName, value, {}, key);
|
@@ -124,7 +122,7 @@ module.exports = async function initFileConf(isVue) {
|
|
124
122
|
|
125
123
|
// 将已有国际化资源的配置发布
|
126
124
|
if (!firstI18n) {
|
127
|
-
const publishTasks = options.supportedLocales.map(key => {
|
125
|
+
const publishTasks = options.supportedLocales.map((key) => {
|
128
126
|
return confService.publishConf(`${key}-test`);
|
129
127
|
});
|
130
128
|
|
@@ -14,7 +14,7 @@ module.exports = async function publish(programOption, env = '') {
|
|
14
14
|
confService = new Conf(options.localeConf);
|
15
15
|
}
|
16
16
|
|
17
|
-
const publishTasks = options.supportedLocales.map(key => {
|
17
|
+
const publishTasks = options.supportedLocales.map((key) => {
|
18
18
|
return confService.publishConf(`${key}-${env}`);
|
19
19
|
});
|
20
20
|
|
@@ -27,11 +27,9 @@ module.exports = class FileConf extends BaseConf {
|
|
27
27
|
* @param {string} key locales标识
|
28
28
|
*/
|
29
29
|
createConf(confName, values, refValues, key) {
|
30
|
-
const folder = (
|
31
|
-
this.localesDir
|
32
|
-
|
33
|
-
: path.join(cwdPath, this.localesDir)
|
34
|
-
);
|
30
|
+
const folder = this.localesDir.startsWith('/')
|
31
|
+
? this.localesDir
|
32
|
+
: path.join(cwdPath, this.localesDir);
|
35
33
|
|
36
34
|
try {
|
37
35
|
fs.accessSync(folder);
|
@@ -41,7 +39,7 @@ module.exports = class FileConf extends BaseConf {
|
|
41
39
|
|
42
40
|
const configFilePath = path.join(folder, `${key}.json`);
|
43
41
|
return new Promise((resolve, reject) => {
|
44
|
-
fs.writeFile(configFilePath, JSON.stringify(values, null, 2), err => {
|
42
|
+
fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
|
45
43
|
if (err) {
|
46
44
|
reject(err);
|
47
45
|
} else {
|
@@ -60,8 +58,8 @@ module.exports = class FileConf extends BaseConf {
|
|
60
58
|
*/
|
61
59
|
updateConf(confName, values, refValues, key) {
|
62
60
|
const configFilePath = path.join(cwdPath, this.localesDir, `${key}.json`);
|
63
|
-
return new Promise(resolve => {
|
64
|
-
fs.writeFile(configFilePath, JSON.stringify(values, null, 2), err => {
|
61
|
+
return new Promise((resolve) => {
|
62
|
+
fs.writeFile(configFilePath, JSON.stringify(values, null, 2), (err) => {
|
65
63
|
if (err) {
|
66
64
|
resolve({
|
67
65
|
code: -1,
|
@@ -92,13 +90,15 @@ module.exports = class FileConf extends BaseConf {
|
|
92
90
|
data = content.length > 0 ? JSON.parse(content) : {};
|
93
91
|
resolve({
|
94
92
|
code: 0,
|
95
|
-
data: Object.keys(data).map(k => ({
|
93
|
+
data: Object.keys(data).map((k) => ({
|
96
94
|
key: k,
|
97
95
|
value: data[k],
|
98
96
|
})),
|
99
97
|
});
|
100
98
|
} catch (err) {
|
101
|
-
reject(
|
99
|
+
reject(
|
100
|
+
new Error(`请检查 ${configFilePath} 资源文件 JSON 格式是否正确`)
|
101
|
+
);
|
102
102
|
}
|
103
103
|
} else {
|
104
104
|
reject(new Error(`资源文件 ${configFilePath} 不存在`));
|
package/zti18n-cli/src/index.js
CHANGED
@@ -3,7 +3,7 @@ const convert = require('./command/convert');
|
|
3
3
|
const convert2 = require('./command/convert2');
|
4
4
|
const collect = require('./command/collect');
|
5
5
|
const publish = require('./command/publish');
|
6
|
-
const option = require('
|
6
|
+
const option = require('../../package.json');
|
7
7
|
|
8
8
|
module.exports = program;
|
9
9
|
|
@@ -26,9 +26,9 @@ program
|
|
26
26
|
console.log(' Examples:');
|
27
27
|
console.log();
|
28
28
|
console.log(' sync without publish:');
|
29
|
-
console.log(' $
|
29
|
+
console.log(' $ zti18n sync -c ./config/prod.config.js');
|
30
30
|
console.log(' sync and then publish:');
|
31
|
-
console.log(' $
|
31
|
+
console.log(' $ zti18n sync -p -c ./config/prod.config.js');
|
32
32
|
console.log();
|
33
33
|
});
|
34
34
|
|
@@ -41,7 +41,7 @@ program
|
|
41
41
|
.on('--help', function () {
|
42
42
|
console.log(' Examples:');
|
43
43
|
console.log();
|
44
|
-
console.log(' $
|
44
|
+
console.log(' $ zti18n publish');
|
45
45
|
console.log();
|
46
46
|
});
|
47
47
|
|
@@ -56,7 +56,7 @@ program
|
|
56
56
|
.on('--help', function () {
|
57
57
|
console.log(' Examples:');
|
58
58
|
console.log();
|
59
|
-
console.log(' $
|
59
|
+
console.log(' $ zti18n convert -c ./config/prod.config.js');
|
60
60
|
console.log();
|
61
61
|
});
|
62
62
|
|
@@ -70,6 +70,6 @@ program
|
|
70
70
|
.on('--help', function () {
|
71
71
|
console.log(' Examples:');
|
72
72
|
console.log();
|
73
|
-
console.log(' $
|
73
|
+
console.log(' $ zti18n convert2 -c ./config/prod.config.js');
|
74
74
|
console.log();
|
75
75
|
});
|
@@ -1,8 +1,8 @@
|
|
1
1
|
const chalk = require('chalk');
|
2
2
|
|
3
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)),
|
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
8
|
};
|
@@ -7,11 +7,11 @@ const cwdPath = process.cwd();
|
|
7
7
|
|
8
8
|
module.exports = function mergeOptions(programOption, programParameter) {
|
9
9
|
const options = defaultOptions;
|
10
|
-
const configFileName = programOption.config || '
|
10
|
+
const configFileName = programOption.config || 'zti18n.config.js';
|
11
11
|
|
12
12
|
const configFilePath = path.join(cwdPath, configFileName);
|
13
13
|
|
14
|
-
// 读取
|
14
|
+
// 读取 zti18n-ast.config.js 中设置的参数,然后并入 options
|
15
15
|
if (fs.existsSync(configFilePath)) {
|
16
16
|
let configurationFile = {};
|
17
17
|
try {
|
@@ -30,7 +30,7 @@ module.exports = function mergeOptions(programOption, programParameter) {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
// 处理命令行参数
|
33
|
-
programParameter.forEach(k => {
|
33
|
+
programParameter.forEach((k) => {
|
34
34
|
const value = programOption[k];
|
35
35
|
if (value) {
|
36
36
|
if (k === 'exclude' && typeof value === 'string') {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
const t = require('@babel/types');
|
2
2
|
const log = require('../utils/log');
|
3
3
|
|
4
|
-
const isChinese = function(text) {
|
4
|
+
const isChinese = function (text) {
|
5
5
|
return /[\u4e00-\u9fa5]/.test(text);
|
6
6
|
};
|
7
7
|
|
@@ -52,7 +52,7 @@ function getPlugin(zhData, outObj) {
|
|
52
52
|
});
|
53
53
|
}
|
54
54
|
|
55
|
-
const plugin = function({ types: t }) {
|
55
|
+
const plugin = function ({ types: t }) {
|
56
56
|
return {
|
57
57
|
visitor: {
|
58
58
|
ImportDeclaration(path) {
|
@@ -80,11 +80,11 @@ function getPlugin(zhData, outObj) {
|
|
80
80
|
|
81
81
|
// 替换类似 this.props.intl.locale === 'en' 为 intl.options.currentLocale === 'en-US'
|
82
82
|
if (
|
83
|
-
node.operator === '==='
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
node.operator === '===' &&
|
84
|
+
node.right.type === 'StringLiteral' &&
|
85
|
+
node.right.value === 'en' &&
|
86
|
+
node.left.type === 'MemberExpression' &&
|
87
|
+
node.left.property.name === 'locale'
|
88
88
|
) {
|
89
89
|
outObj.needRewrite = true;
|
90
90
|
log.info("replace intl.locale === 'en'");
|
@@ -105,15 +105,15 @@ function getPlugin(zhData, outObj) {
|
|
105
105
|
}
|
106
106
|
|
107
107
|
if (
|
108
|
-
(parent.init.type === 'Identifier'
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
(parent.init.type === 'Identifier' &&
|
109
|
+
parent.init.name === 'props') ||
|
110
|
+
(parent.init.type === 'MemberExpression' &&
|
111
|
+
parent.init.property.name === 'props')
|
112
112
|
) {
|
113
113
|
// 处理掉 let { params, intl } = this.props; 中的 intl
|
114
114
|
log.info('remove: this.props.intl');
|
115
115
|
node.properties = node.properties.filter(
|
116
|
-
p => !p.value || p.value.name !== 'intl'
|
116
|
+
(p) => !p.value || p.value.name !== 'intl'
|
117
117
|
);
|
118
118
|
}
|
119
119
|
},
|
@@ -124,7 +124,7 @@ function getPlugin(zhData, outObj) {
|
|
124
124
|
outObj.needRewrite = true;
|
125
125
|
|
126
126
|
const idNode = openingElement.attributes.find(
|
127
|
-
atr => atr.name.name === 'id'
|
127
|
+
(atr) => atr.name.name === 'id'
|
128
128
|
);
|
129
129
|
|
130
130
|
const id = idNode.value.value
|
@@ -132,7 +132,7 @@ function getPlugin(zhData, outObj) {
|
|
132
132
|
: idNode.value.expression;
|
133
133
|
|
134
134
|
const valuesNode = openingElement.attributes.find(
|
135
|
-
atr => atr.name.name === 'values'
|
135
|
+
(atr) => atr.name.name === 'values'
|
136
136
|
);
|
137
137
|
let callExpression;
|
138
138
|
|
@@ -173,7 +173,7 @@ function getPlugin(zhData, outObj) {
|
|
173
173
|
|
174
174
|
const handleFormatMessageMethod = () => {
|
175
175
|
const id = node.arguments[0].properties.find(
|
176
|
-
prop => prop.key.name === 'id'
|
176
|
+
(prop) => prop.key.name === 'id'
|
177
177
|
).value.value;
|
178
178
|
outObj.needRewrite = true;
|
179
179
|
|
@@ -197,10 +197,10 @@ function getPlugin(zhData, outObj) {
|
|
197
197
|
if (node.callee.type === 'MemberExpression') {
|
198
198
|
if (node.callee.property.name === 'formatMessage') {
|
199
199
|
if (
|
200
|
-
(node.callee.object.property
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
(node.callee.object.property &&
|
201
|
+
node.callee.object.property.name === 'intl') ||
|
202
|
+
(node.callee.object.type === 'Identifier' &&
|
203
|
+
node.callee.object.name === 'intl')
|
204
204
|
) {
|
205
205
|
handleFormatMessageMethod();
|
206
206
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const t = require('@babel/types');
|
2
2
|
|
3
|
-
const replaceLineBreak = function(value) {
|
3
|
+
const replaceLineBreak = function (value) {
|
4
4
|
if (typeof value !== 'string') return value;
|
5
5
|
return value.replace(/\n/g, ' ');
|
6
6
|
};
|
@@ -30,14 +30,17 @@ function getPlugin(outObj, allConverted, intlAlias = 'intl') {
|
|
30
30
|
);
|
31
31
|
}
|
32
32
|
|
33
|
-
const plugin = function() {
|
33
|
+
const plugin = function () {
|
34
34
|
return {
|
35
35
|
visitor: {
|
36
36
|
CallExpression(path) {
|
37
37
|
const { node } = path;
|
38
38
|
|
39
39
|
if (node.callee.type === 'MemberExpression') {
|
40
|
-
if (
|
40
|
+
if (
|
41
|
+
path.node.callee.object.name === intlAlias &&
|
42
|
+
path.node.callee.property.name === 'get'
|
43
|
+
) {
|
41
44
|
const args = path.node.arguments;
|
42
45
|
|
43
46
|
const orignKey = args[0].value;
|
@@ -45,7 +48,9 @@ function getPlugin(outObj, allConverted, intlAlias = 'intl') {
|
|
45
48
|
|
46
49
|
const value = path.parentPath.parent.arguments[0].value;
|
47
50
|
|
48
|
-
path.parentPath.parentPath.replaceWith(
|
51
|
+
path.parentPath.parentPath.replaceWith(
|
52
|
+
makeReplace({ orignKey, value, variableObj })
|
53
|
+
);
|
49
54
|
}
|
50
55
|
}
|
51
56
|
},
|
@@ -1,79 +1,79 @@
|
|
1
1
|
// 当使用 HTML 模板时,由于大小写不敏感,为了避免转换中丢失大小写,需要提供组件的 Pascal 到 kebab 形式映射
|
2
2
|
// 默认的如下(iview: https://github.com/iview/iview-loader/blob/master/src/tag-map.js)
|
3
3
|
module.exports = {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
4
|
+
Switch: 'i-switch',
|
5
|
+
Circle: 'i-circle',
|
6
|
+
Affix: 'i-affix',
|
7
|
+
Alert: 'i-alert',
|
8
|
+
AnchorLink: 'i-anchor-link',
|
9
|
+
Anchor: 'i-anchor',
|
10
|
+
AutoComplete: 'i-auto-complete',
|
11
|
+
Avatar: 'i-avatar',
|
12
|
+
BackTop: 'i-back-top',
|
13
|
+
Badge: 'i-badge',
|
14
|
+
BreadcrumbItem: 'i-breadcrumb-item',
|
15
|
+
Breadcrumb: 'i-breadcrumb',
|
16
|
+
ButtonGroup: 'i-button-group',
|
17
|
+
Button: 'i-button',
|
18
|
+
Card: 'i-card',
|
19
|
+
CarouselItem: 'i-carousel-item',
|
20
|
+
Carousel: 'i-carousel',
|
21
|
+
Cascader: 'i-cascader',
|
22
|
+
CellGroup: 'i-cell-group',
|
23
|
+
Cell: 'i-cell',
|
24
|
+
CheckboxGroup: 'i-checkbox-group',
|
25
|
+
Checkbox: 'i-checkbox',
|
26
|
+
Col: 'i-col',
|
27
|
+
Collapse: 'i-collapse',
|
28
|
+
ColorPicker: 'i-color-picker',
|
29
|
+
Content: 'i-content',
|
30
|
+
DatePicker: 'i-date-picker',
|
31
|
+
Divider: 'i-divider',
|
32
|
+
Drawer: 'i-drawer',
|
33
|
+
DropdownItem: 'i-dropdown-item',
|
34
|
+
DropdownMenu: 'i-dropdown-menu',
|
35
|
+
Dropdown: 'i-dropdown',
|
36
|
+
Footer: 'i-footer',
|
37
|
+
FormItem: 'i-form-item',
|
38
|
+
Form: 'i-form',
|
39
|
+
Header: 'i-header',
|
40
|
+
Icon: 'i-icon',
|
41
|
+
InputNumber: 'i-input-number',
|
42
|
+
Input: 'i-input',
|
43
|
+
Layout: 'i-layout',
|
44
|
+
Menu: 'i-menu',
|
45
|
+
MenuGroup: 'i-menu-group',
|
46
|
+
MenuItem: 'i-menu-item',
|
47
|
+
Sider: 'i-sider',
|
48
|
+
Submenu: 'i-submenu',
|
49
|
+
Modal: 'i-modal',
|
50
|
+
OptionGroup: 'i-option-group',
|
51
|
+
Option: 'i-option',
|
52
|
+
Page: 'i-page',
|
53
|
+
Panel: 'i-panel',
|
54
|
+
Poptip: 'i-poptip',
|
55
|
+
Progress: 'i-progress',
|
56
|
+
RadioGroup: 'i-radio-group',
|
57
|
+
Radio: 'i-radio',
|
58
|
+
Rate: 'i-rate',
|
59
|
+
Row: 'i-row',
|
60
|
+
Scroll: 'i-scroll',
|
61
|
+
Select: 'i-select',
|
62
|
+
Slider: 'i-slider',
|
63
|
+
Spin: 'i-spin',
|
64
|
+
Split: 'i-split',
|
65
|
+
Step: 'i-step',
|
66
|
+
Steps: 'i-steps',
|
67
|
+
Table: 'i-table',
|
68
|
+
Tabs: 'i-tabs',
|
69
|
+
TabPane: 'i-tab-pane',
|
70
|
+
Tag: 'i-tag',
|
71
|
+
TimelineItem: 'i-timeline-item',
|
72
|
+
Timeline: 'i-timeline',
|
73
|
+
TimePicker: 'i-time-picker',
|
74
|
+
Time: 'i-time',
|
75
|
+
Tooltip: 'i-tooltip',
|
76
|
+
Transfer: 'i-transfer',
|
77
|
+
Tree: 'i-tree',
|
78
|
+
Upload: 'i-upload',
|
79
79
|
};
|
@@ -50,12 +50,10 @@ function parse5Serialize(node, options) {
|
|
50
50
|
function toKebab(tpl, pkMap = {}) {
|
51
51
|
pkMap = { ...defaultPkMap, ...pkMap };
|
52
52
|
|
53
|
-
Object.keys(pkMap).forEach(i => {
|
54
|
-
tpl =
|
55
|
-
|
56
|
-
|
57
|
-
.replace(new RegExp(`</${i}>`, 'g'), `</${pkMap[i]}>`)
|
58
|
-
);
|
53
|
+
Object.keys(pkMap).forEach((i) => {
|
54
|
+
tpl = tpl
|
55
|
+
.replace(new RegExp(`<${i}(?![a-zA-Z0-9-])`, 'g'), `<${pkMap[i]}`)
|
56
|
+
.replace(new RegExp(`</${i}>`, 'g'), `</${pkMap[i]}>`);
|
59
57
|
});
|
60
58
|
return tpl;
|
61
59
|
}
|
@@ -63,28 +61,22 @@ function toKebab(tpl, pkMap = {}) {
|
|
63
61
|
function toPascal(tpl, pkMap = {}) {
|
64
62
|
pkMap = { ...defaultPkMap, ...pkMap };
|
65
63
|
|
66
|
-
Object.keys(pkMap).forEach(i => {
|
67
|
-
tpl =
|
68
|
-
|
69
|
-
|
70
|
-
.replace(new RegExp(`</${pkMap[i]}>`, 'g'), `</${i}>`)
|
71
|
-
);
|
64
|
+
Object.keys(pkMap).forEach((i) => {
|
65
|
+
tpl = tpl
|
66
|
+
.replace(new RegExp(`<${pkMap[i]}(?![a-zA-Z0-9-])`, 'g'), `<${i}`)
|
67
|
+
.replace(new RegExp(`</${pkMap[i]}>`, 'g'), `</${i}>`);
|
72
68
|
});
|
73
69
|
return tpl;
|
74
70
|
}
|
75
71
|
|
76
|
-
function traverseHtml(ast, {
|
77
|
-
primaryRegx,
|
78
|
-
i18nMethod,
|
79
|
-
ignoreLines,
|
80
|
-
}, returns) {
|
72
|
+
function traverseHtml(ast, { primaryRegx, i18nMethod, ignoreLines }, returns) {
|
81
73
|
const { allTranslated, allUpdated, allUsedKeys } = returns;
|
82
74
|
const existValues = Object.keys(allTranslated);
|
83
75
|
|
84
76
|
function shouldIgnore(node) {
|
85
77
|
return (
|
86
|
-
node.sourceCodeLocation
|
87
|
-
|
78
|
+
node.sourceCodeLocation &&
|
79
|
+
ignoreLines.includes(node.sourceCodeLocation.startLine)
|
88
80
|
);
|
89
81
|
}
|
90
82
|
|
@@ -135,27 +127,33 @@ function traverseHtml(ast, {
|
|
135
127
|
|
136
128
|
if (!hasTouch) return source;
|
137
129
|
|
138
|
-
return prettier
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
130
|
+
return prettier
|
131
|
+
.format(source1, {
|
132
|
+
parser: 'babel',
|
133
|
+
singleQuote: true,
|
134
|
+
semi: false,
|
135
|
+
})
|
136
|
+
.trim();
|
143
137
|
}
|
144
138
|
|
145
139
|
function traverse(node) {
|
146
140
|
if (node.childNodes) {
|
147
|
-
node.childNodes.forEach(childNode => traverse(childNode));
|
141
|
+
node.childNodes.forEach((childNode) => traverse(childNode));
|
148
142
|
}
|
149
143
|
|
150
144
|
// 处理属性
|
151
145
|
if (!shouldIgnore(node) && node.attrs) {
|
152
|
-
node.attrs.forEach(attr => {
|
146
|
+
node.attrs.forEach((attr) => {
|
153
147
|
const { name, value } = attr;
|
154
148
|
|
155
149
|
// 非主语言或空,跳过
|
156
150
|
if (!isPrimary(value) || !value) return;
|
157
151
|
|
158
|
-
if (
|
152
|
+
if (
|
153
|
+
name.startsWith('v-') ||
|
154
|
+
name.startsWith(':') ||
|
155
|
+
name.startsWith('@')
|
156
|
+
) {
|
159
157
|
// vue 指令
|
160
158
|
// 引号里是 js 表达式,直接调用 transformJs 来转换
|
161
159
|
const source = transformJsExpression(value);
|
@@ -213,11 +211,11 @@ function traverseHtml(ast, {
|
|
213
211
|
}
|
214
212
|
|
215
213
|
// 可能有 #comment 节点,需要找到 html 节点
|
216
|
-
const html = ast.childNodes.find(nd => nd.nodeName === 'html');
|
214
|
+
const html = ast.childNodes.find((nd) => nd.nodeName === 'html');
|
217
215
|
|
218
216
|
if (html) {
|
219
217
|
// 再找 body 节点
|
220
|
-
const body = html.childNodes.find(nd => nd.nodeName === 'body');
|
218
|
+
const body = html.childNodes.find((nd) => nd.nodeName === 'body');
|
221
219
|
|
222
220
|
// 遍历
|
223
221
|
if (body) traverse(body);
|
@@ -225,11 +223,7 @@ function traverseHtml(ast, {
|
|
225
223
|
}
|
226
224
|
|
227
225
|
module.exports = function transformHtml(source, localeInfo = {}, options = {}) {
|
228
|
-
const {
|
229
|
-
allTranslated = {},
|
230
|
-
allUpdated = {},
|
231
|
-
allUsedKeys = [],
|
232
|
-
} = localeInfo;
|
226
|
+
const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
|
233
227
|
|
234
228
|
const {
|
235
229
|
primaryRegx = /[\u4e00-\u9fa5]/,
|
@@ -261,7 +255,9 @@ module.exports = function transformHtml(source, localeInfo = {}, options = {}) {
|
|
261
255
|
|
262
256
|
opts.ignoreLines = getIgnoreLines(source);
|
263
257
|
|
264
|
-
const ast = parse5.parse(toKebab(source, pkMap), {
|
258
|
+
const ast = parse5.parse(toKebab(source, pkMap), {
|
259
|
+
sourceCodeLocationInfo: true,
|
260
|
+
});
|
265
261
|
traverseHtml(ast, opts, r);
|
266
262
|
|
267
263
|
let code = toPascal(parse5Serialize(ast), pkMap);
|
@@ -53,16 +53,19 @@ function getIgnoreLines(ast) {
|
|
53
53
|
return ignoreLines;
|
54
54
|
}
|
55
55
|
|
56
|
-
function makeVisitor(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
function makeVisitor(
|
57
|
+
{
|
58
|
+
primaryRegx,
|
59
|
+
i18nObject,
|
60
|
+
i18nMethod,
|
61
|
+
importCode,
|
62
|
+
ignoreLines,
|
63
|
+
ignoreMethods,
|
64
|
+
ignoreComponents,
|
65
|
+
ignoreAttributes,
|
66
|
+
},
|
67
|
+
returns
|
68
|
+
) {
|
66
69
|
const { allTranslated, allUpdated, allUsedKeys } = returns;
|
67
70
|
const existValues = Object.keys(allTranslated);
|
68
71
|
const hacked = {};
|
@@ -99,7 +102,7 @@ function makeVisitor({
|
|
99
102
|
function makeObjectExpression(obj) {
|
100
103
|
if (Object.prototype.toString.call(obj) === '[object Object]') {
|
101
104
|
const ObjectPropertyArr = [];
|
102
|
-
Object.keys(obj).forEach(k => {
|
105
|
+
Object.keys(obj).forEach((k) => {
|
103
106
|
ObjectPropertyArr.push(
|
104
107
|
t.ObjectProperty(
|
105
108
|
t.Identifier(k),
|
@@ -144,10 +147,7 @@ function makeVisitor({
|
|
144
147
|
|
145
148
|
if (i18nObject) {
|
146
149
|
return t.callExpression(
|
147
|
-
t.memberExpression(
|
148
|
-
t.identifier(i18nObject),
|
149
|
-
t.identifier(i18nMethod)
|
150
|
-
),
|
150
|
+
t.memberExpression(t.identifier(i18nObject), t.identifier(i18nMethod)),
|
151
151
|
objExp ? [v, objExp] : [v]
|
152
152
|
);
|
153
153
|
}
|
@@ -173,8 +173,8 @@ function makeVisitor({
|
|
173
173
|
const { node } = path;
|
174
174
|
|
175
175
|
if (
|
176
|
-
!shouldIgnore(node)
|
177
|
-
|
176
|
+
!shouldIgnore(node) &&
|
177
|
+
node.quasis.some((word) => isPrimary(word.value.cooked))
|
178
178
|
) {
|
179
179
|
const tempArr = [...node.quasis, ...node.expressions];
|
180
180
|
tempArr.sort((a, b) => a.start - b.start);
|
@@ -184,29 +184,27 @@ function makeVisitor({
|
|
184
184
|
let needReplace = false;
|
185
185
|
let slotIndex = 0;
|
186
186
|
|
187
|
-
tempArr.forEach(function(nd) {
|
187
|
+
tempArr.forEach(function (nd) {
|
188
188
|
if (nd.type === 'TemplateElement') {
|
189
189
|
value += nd.value.cooked;
|
190
190
|
if (isPrimary(nd.value.cooked)) {
|
191
191
|
needReplace = true;
|
192
192
|
}
|
193
193
|
} else if (nd.type === 'Identifier') {
|
194
|
-
value += `{${nd.name}}`;
|
194
|
+
value += `{{${nd.name}}}`;
|
195
195
|
variable[nd.name] = nd.name;
|
196
196
|
needReplace = true;
|
197
197
|
} else {
|
198
198
|
// 例如 CallExpression 等
|
199
199
|
const identifier = `slot${slotIndex++}`;
|
200
|
-
value += `{${identifier}}`;
|
200
|
+
value += `{{${identifier}}}`;
|
201
201
|
variable[identifier] = { isAstNode: true, value: nd };
|
202
202
|
needReplace = true;
|
203
203
|
}
|
204
204
|
});
|
205
205
|
|
206
206
|
if (needReplace && value.trim()) {
|
207
|
-
path.replaceWith(
|
208
|
-
makeReplace(value, variable)
|
209
|
-
);
|
207
|
+
path.replaceWith(makeReplace(value, variable));
|
210
208
|
}
|
211
209
|
}
|
212
210
|
path.skip();
|
@@ -216,14 +214,14 @@ function makeVisitor({
|
|
216
214
|
const { node } = path;
|
217
215
|
const { value } = node;
|
218
216
|
|
219
|
-
const isTsLiteralType =
|
217
|
+
const isTsLiteralType =
|
218
|
+
node.type === 'StringLiteral' &&
|
219
|
+
['TSLiteralType', 'TSEnumMember'].includes(path.parent.type);
|
220
220
|
if (!shouldIgnore(node) && isPrimary(node.value) && !isTsLiteralType) {
|
221
221
|
switch (path.parent.type) {
|
222
222
|
case 'ObjectProperty':
|
223
223
|
case 'AssignmentExpression':
|
224
|
-
path.replaceWith(
|
225
|
-
makeReplace(value)
|
226
|
-
);
|
224
|
+
path.replaceWith(makeReplace(value));
|
227
225
|
break;
|
228
226
|
case 'CallExpression':
|
229
227
|
let v = value;
|
@@ -233,9 +231,7 @@ function makeVisitor({
|
|
233
231
|
v = allUpdated[value];
|
234
232
|
}
|
235
233
|
|
236
|
-
path.replaceWith(
|
237
|
-
makeReplace(v)
|
238
|
-
);
|
234
|
+
path.replaceWith(makeReplace(v));
|
239
235
|
break;
|
240
236
|
case 'NewExpression':
|
241
237
|
// XXX: 会出现吗?
|
@@ -251,17 +247,11 @@ function makeVisitor({
|
|
251
247
|
// );
|
252
248
|
// }
|
253
249
|
} else {
|
254
|
-
path.replaceWith(
|
255
|
-
t.JSXExpressionContainer(
|
256
|
-
makeReplace(value)
|
257
|
-
)
|
258
|
-
);
|
250
|
+
path.replaceWith(t.JSXExpressionContainer(makeReplace(value)));
|
259
251
|
}
|
260
252
|
break;
|
261
253
|
default:
|
262
|
-
path.replaceWith(
|
263
|
-
makeReplace(value)
|
264
|
-
);
|
254
|
+
path.replaceWith(makeReplace(value));
|
265
255
|
break;
|
266
256
|
}
|
267
257
|
|
@@ -306,15 +296,10 @@ function makeVisitor({
|
|
306
296
|
|
307
297
|
// 可能需要更新 key
|
308
298
|
if (
|
309
|
-
(
|
310
|
-
node.callee.
|
311
|
-
|
312
|
-
|
313
|
-
)
|
314
|
-
|| (
|
315
|
-
node.callee.type === 'Identifier'
|
316
|
-
&& node.callee.name === i18nMethod
|
317
|
-
)
|
299
|
+
(node.callee.type === 'MemberExpression' &&
|
300
|
+
node.callee.object.name === i18nObject &&
|
301
|
+
node.callee.property.name === i18nMethod) ||
|
302
|
+
(node.callee.type === 'Identifier' && node.callee.name === i18nMethod)
|
318
303
|
) {
|
319
304
|
// 收集现有的 key
|
320
305
|
const args = node.arguments;
|
@@ -333,9 +318,7 @@ function makeVisitor({
|
|
333
318
|
|
334
319
|
if (allUpdated.hasOwnProperty(key)) {
|
335
320
|
// 如果对应的中文已经在远端被修改,则自动更新代码
|
336
|
-
path.replaceWith(
|
337
|
-
makeReplace(allUpdated[key], variable)
|
338
|
-
);
|
321
|
+
path.replaceWith(makeReplace(allUpdated[key], variable));
|
339
322
|
} else {
|
340
323
|
if (Array.isArray(node.arguments) && node.arguments.length > 0) {
|
341
324
|
if (!allUsedKeys.includes(key)) {
|
@@ -367,7 +350,9 @@ function makeVisitor({
|
|
367
350
|
if (!node.ignore && !shouldIgnore(node)) {
|
368
351
|
const { openingElement } = node;
|
369
352
|
if (openingElement.name.name === 'Di18nTrans') {
|
370
|
-
const keyAtr = openingElement.attributes.find(
|
353
|
+
const keyAtr = openingElement.attributes.find(
|
354
|
+
(atr) => atr.name.name === 'i18nKey'
|
355
|
+
);
|
371
356
|
if (!keyAtr) return;
|
372
357
|
|
373
358
|
const key = keyAtr.value.value;
|
@@ -386,7 +371,12 @@ function makeVisitor({
|
|
386
371
|
if (cur.type === 'JSXElement') {
|
387
372
|
// 内部的文案加上标记,不再检测
|
388
373
|
cur.children[0].ignore = true;
|
389
|
-
return
|
374
|
+
return (
|
375
|
+
prev +
|
376
|
+
formatWhitespace(
|
377
|
+
`<${index}>${cur.children[0].value}</${index}>`
|
378
|
+
)
|
379
|
+
);
|
390
380
|
}
|
391
381
|
|
392
382
|
console.error(`${cur.type} node are not supported in Di18nTrans`);
|
@@ -405,11 +395,7 @@ function makeVisitor({
|
|
405
395
|
|
406
396
|
if (!node.ignore && !shouldIgnore(node) && isPrimary(node.value)) {
|
407
397
|
// 将中文替换为 JSX 表达式
|
408
|
-
path.replaceWith(
|
409
|
-
t.JSXExpressionContainer(
|
410
|
-
makeReplace(node.value)
|
411
|
-
)
|
412
|
-
);
|
398
|
+
path.replaceWith(t.JSXExpressionContainer(makeReplace(node.value)));
|
413
399
|
}
|
414
400
|
|
415
401
|
path.skip();
|
@@ -427,11 +413,7 @@ function makeVisitor({
|
|
427
413
|
}
|
428
414
|
|
429
415
|
module.exports = function transformJs(source, localeInfo = {}, options = {}) {
|
430
|
-
const {
|
431
|
-
allTranslated = {},
|
432
|
-
allUpdated = {},
|
433
|
-
allUsedKeys = [],
|
434
|
-
} = localeInfo;
|
416
|
+
const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
|
435
417
|
|
436
418
|
const {
|
437
419
|
primaryRegx = /[\u4e00-\u9fa5]/,
|
@@ -490,7 +472,11 @@ module.exports = function transformJs(source, localeInfo = {}, options = {}) {
|
|
490
472
|
traverse(ast, visitor);
|
491
473
|
|
492
474
|
// https://stackoverflow.com/a/55478641
|
493
|
-
let { code } = generate(
|
475
|
+
let { code } = generate(
|
476
|
+
ast,
|
477
|
+
{ retainLines: true, decoratorsBeforeExport: true },
|
478
|
+
source
|
479
|
+
);
|
494
480
|
|
495
481
|
if (!r.hasTouch) {
|
496
482
|
code = source;
|
@@ -8,44 +8,55 @@ const getIgnoreLines = require('../utils/getIgnoreLines');
|
|
8
8
|
|
9
9
|
/* eslint-disable */
|
10
10
|
// override to avoid unneeded escape: pug-source-gen/lib/code-generator.js
|
11
|
-
genSource.CodeGenerator.prototype.attrs = function(attrs) {
|
11
|
+
genSource.CodeGenerator.prototype.attrs = function (attrs) {
|
12
12
|
var regularAttrs = [];
|
13
13
|
var classes = '';
|
14
14
|
var id;
|
15
|
-
attrs.forEach(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
attrs.forEach(
|
16
|
+
function (attr) {
|
17
|
+
var constVal = '';
|
18
|
+
try {
|
19
|
+
constVal = constantinople.toConstant(attr.val);
|
20
|
+
} catch (ex) {}
|
21
|
+
|
22
|
+
if (
|
23
|
+
attr.name === 'class' &&
|
24
|
+
!attr.escaped &&
|
25
|
+
constVal &&
|
26
|
+
/^\-?[_a-z][_a-z0-9\-]*$/i.test(constVal)
|
27
|
+
) {
|
28
|
+
classes += '.' + constVal;
|
29
|
+
} else if (
|
30
|
+
attr.name === 'id' &&
|
31
|
+
!id &&
|
32
|
+
!attr.escaped &&
|
33
|
+
constVal &&
|
34
|
+
/^[\w-]+$/.test(constVal)
|
35
|
+
) {
|
36
|
+
id = constVal;
|
33
37
|
} else {
|
34
|
-
var
|
35
|
-
attrOut += name;
|
36
|
-
}
|
38
|
+
var attrOut = '';
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
// name
|
41
|
+
if (/^\w[^()[\]=!,`'"\s]*$/.test(attr.name)) {
|
42
|
+
attrOut += attr.name;
|
43
|
+
} else {
|
44
|
+
var name = attr.name.replace(/\\/g, '\\\\');
|
45
|
+
attrOut += name;
|
46
|
+
}
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
if (!(typeof constVal === 'boolean' && constVal === true)) {
|
49
|
+
// operator
|
50
|
+
attrOut += '=';
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
// value
|
53
|
+
attrOut += attr.val;
|
54
|
+
}
|
55
|
+
|
56
|
+
regularAttrs.push(attrOut);
|
57
|
+
}
|
58
|
+
}.bind(this)
|
59
|
+
);
|
49
60
|
|
50
61
|
var out = '';
|
51
62
|
if (id) out += '#' + id;
|
@@ -53,14 +64,11 @@ genSource.CodeGenerator.prototype.attrs = function(attrs) {
|
|
53
64
|
if (regularAttrs.length) out += '(' + regularAttrs.join(' ') + ')';
|
54
65
|
|
55
66
|
return out;
|
56
|
-
}
|
67
|
+
};
|
57
68
|
/* eslint-enable */
|
58
69
|
|
59
|
-
function traversePug(ast, {
|
60
|
-
|
61
|
-
i18nMethod,
|
62
|
-
ignoreLines,
|
63
|
-
}, returns) { // returesallTranslatedWord, updatedTranslatedWord, keysInUse, ignores) {
|
70
|
+
function traversePug(ast, { primaryRegx, i18nMethod, ignoreLines }, returns) {
|
71
|
+
// returesallTranslatedWord, updatedTranslatedWord, keysInUse, ignores) {
|
64
72
|
const { allTranslated, allUpdated, allUsedKeys } = returns;
|
65
73
|
const existValues = Object.keys(allTranslated);
|
66
74
|
|
@@ -133,18 +141,22 @@ function traversePug(ast, {
|
|
133
141
|
}
|
134
142
|
|
135
143
|
if (node.type === 'Block' && node.nodes) {
|
136
|
-
node.nodes.forEach(nd => traverse(nd));
|
144
|
+
node.nodes.forEach((nd) => traverse(nd));
|
137
145
|
}
|
138
146
|
|
139
147
|
// 处理属性
|
140
148
|
if (!shouldIgnore(node) && node.attrs) {
|
141
|
-
node.attrs.forEach(attr => {
|
149
|
+
node.attrs.forEach((attr) => {
|
142
150
|
const { name, val } = attr;
|
143
151
|
|
144
152
|
// 非主语言,跳过
|
145
153
|
if (!isPrimary(val)) return;
|
146
154
|
|
147
|
-
if (
|
155
|
+
if (
|
156
|
+
name.startsWith('v-') ||
|
157
|
+
name.startsWith(':') ||
|
158
|
+
name.startsWith('@')
|
159
|
+
) {
|
148
160
|
// vue 指令
|
149
161
|
let value = val;
|
150
162
|
if (['"', "'"].includes(val.charAt(0))) {
|
@@ -210,11 +222,7 @@ function traversePug(ast, {
|
|
210
222
|
}
|
211
223
|
|
212
224
|
module.exports = function transformPug(source, localeInfo = {}, options = {}) {
|
213
|
-
const {
|
214
|
-
allTranslated = {},
|
215
|
-
allUpdated = {},
|
216
|
-
allUsedKeys = [],
|
217
|
-
} = localeInfo;
|
225
|
+
const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
|
218
226
|
|
219
227
|
const {
|
220
228
|
primaryRegx = /[\u4e00-\u9fa5]/,
|
@@ -252,10 +260,12 @@ module.exports = function transformPug(source, localeInfo = {}, options = {}) {
|
|
252
260
|
let code = source;
|
253
261
|
if (r.hasTouch) {
|
254
262
|
const genCode = genSource(ast);
|
255
|
-
code = prettier
|
256
|
-
|
257
|
-
|
258
|
-
|
263
|
+
code = prettier
|
264
|
+
.format(genCode, {
|
265
|
+
filepath: 'xxx.pug',
|
266
|
+
pugAttributeSeparator: 'none',
|
267
|
+
})
|
268
|
+
.trim();
|
259
269
|
}
|
260
270
|
|
261
271
|
return { source: code, hasTouch: r.hasTouch };
|
@@ -39,7 +39,7 @@ module.exports = function transformReactIntlToReactIntlUniversal(option) {
|
|
39
39
|
|
40
40
|
let zhData = {};
|
41
41
|
|
42
|
-
targetLocales.forEach(element => {
|
42
|
+
targetLocales.forEach((element) => {
|
43
43
|
if (path.extname(element) === '.json') {
|
44
44
|
const json = fs.readFileSync(element, {
|
45
45
|
encoding: 'utf-8',
|
@@ -88,7 +88,7 @@ module.exports = function transformReactIntlToReactIntlUniversal(option) {
|
|
88
88
|
}
|
89
89
|
}
|
90
90
|
|
91
|
-
targetFiles.forEach(element => {
|
91
|
+
targetFiles.forEach((element) => {
|
92
92
|
log.info(`start: ${element}`);
|
93
93
|
transformFile(element);
|
94
94
|
log.success(`done: ${element}`);
|
@@ -73,7 +73,7 @@ module.exports = function transformReactIntlUniveralToDi18n(option) {
|
|
73
73
|
|
74
74
|
const outputs = output ? [].concat(output) : [];
|
75
75
|
const targetFiles = [].concat(entry).reduce((prev, cur, index) => {
|
76
|
-
const files = getSourceFiles({ entry: cur, exclude }).map(file => ({
|
76
|
+
const files = getSourceFiles({ entry: cur, exclude }).map((file) => ({
|
77
77
|
filePath: file,
|
78
78
|
currentEntry: cur,
|
79
79
|
currentOutput: outputs[index],
|
@@ -81,7 +81,7 @@ module.exports = function transformReactIntlUniveralToDi18n(option) {
|
|
81
81
|
return prev.concat(files);
|
82
82
|
}, []);
|
83
83
|
|
84
|
-
targetFiles.forEach(codeFileInfo => {
|
84
|
+
targetFiles.forEach((codeFileInfo) => {
|
85
85
|
translate(codeFileInfo, allConverted, option);
|
86
86
|
log.success(`done: ${codeFileInfo.filePath}`);
|
87
87
|
});
|
@@ -2,11 +2,7 @@ const presetTypescript = require('@babel/preset-typescript').default;
|
|
2
2
|
const transformJs = require('./transformJs');
|
3
3
|
|
4
4
|
module.exports = function transformTs(code, localeInfo = {}, options = {}) {
|
5
|
-
const {
|
6
|
-
allTranslated = {},
|
7
|
-
allUpdated = {},
|
8
|
-
allUsedKeys = [],
|
9
|
-
} = localeInfo;
|
5
|
+
const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
|
10
6
|
|
11
7
|
const {
|
12
8
|
primaryRegx = /[\u4e00-\u9fa5]/,
|
@@ -30,16 +30,14 @@ function closeTag(sfcBlock) {
|
|
30
30
|
|
31
31
|
function combineVue(template, script, sytles, customBlocks) {
|
32
32
|
return [template, script, ...sytles, ...customBlocks]
|
33
|
-
.map(
|
33
|
+
.map((sfc) =>
|
34
|
+
sfc ? `${openTag(sfc)}\n${sfc.content.trim()}\n${closeTag(sfc)}\n` : ''
|
35
|
+
)
|
34
36
|
.join('\n');
|
35
37
|
}
|
36
38
|
|
37
39
|
module.exports = function transformVue(source, localeInfo = {}, options = {}) {
|
38
|
-
const {
|
39
|
-
allTranslated = {},
|
40
|
-
allUpdated = {},
|
41
|
-
allUsedKeys = [],
|
42
|
-
} = localeInfo;
|
40
|
+
const { allTranslated = {}, allUpdated = {}, allUsedKeys = [] } = localeInfo;
|
43
41
|
|
44
42
|
const {
|
45
43
|
primaryRegx = /[\u4e00-\u9fa5]/,
|
@@ -91,7 +89,9 @@ module.exports = function transformVue(source, localeInfo = {}, options = {}) {
|
|
91
89
|
template.content = ret.source;
|
92
90
|
hasTouch = ret.hasTouch;
|
93
91
|
} else {
|
94
|
-
console.warn(
|
92
|
+
console.warn(
|
93
|
+
`Unsupport type: ${templateType}, so the template is ignored`
|
94
|
+
);
|
95
95
|
}
|
96
96
|
}
|
97
97
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
const chalk = require('chalk');
|
2
2
|
|
3
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)),
|
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
8
|
};
|