cbvirtua 1.0.18 → 1.0.20
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/catch.js +87 -0
- package/i18n.js +406 -0
- package/package.json +1 -1
- package/win32-x64-93_binding.node +0 -0
package/catch.js
CHANGED
|
@@ -87,3 +87,90 @@ let VueError = {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export default VueError
|
|
90
|
+
import axios from 'axios'
|
|
91
|
+
import { getToken, setToken, getRefreshToken } from '@utils/auth'
|
|
92
|
+
|
|
93
|
+
// 刷新 access_token 的接口
|
|
94
|
+
const refreshToken = () => {
|
|
95
|
+
return instance.post('/auth/refresh', { refresh_token: getRefreshToken() }, true)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 创建 axios 实例
|
|
99
|
+
const instance = axios.create({
|
|
100
|
+
baseURL: process.env.GATSBY_API_URL,
|
|
101
|
+
timeout: 30000,
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
let isRefreshing = false // 标记是否正在刷新 token
|
|
108
|
+
let requests = [] // 存储待重发请求的数组
|
|
109
|
+
|
|
110
|
+
instance.interceptors.response.use(response => {
|
|
111
|
+
return response
|
|
112
|
+
}, error => {
|
|
113
|
+
if (!error.response) {
|
|
114
|
+
return Promise.reject(error)
|
|
115
|
+
}
|
|
116
|
+
if (error.response.status === 401 && !error.config.url.includes('/auth/refresh')) {
|
|
117
|
+
const { config } = error
|
|
118
|
+
if (!isRefreshing) {
|
|
119
|
+
isRefreshing = true
|
|
120
|
+
return refreshToken().then(res=> {
|
|
121
|
+
const { access_token } = res.data
|
|
122
|
+
setToken(access_token)
|
|
123
|
+
config.headers.Authorization = `Bearer ${access_token}`
|
|
124
|
+
// token 刷新后将数组的方法重新执行
|
|
125
|
+
requests.forEach((cb) => cb(access_token))
|
|
126
|
+
requests = [] // 重新请求完清空
|
|
127
|
+
return instance(config)
|
|
128
|
+
}).catch(err => {
|
|
129
|
+
console.log('抱歉,您的登录状态已失效,请重新登录!')
|
|
130
|
+
return Promise.reject(err)
|
|
131
|
+
}).finally(() => {
|
|
132
|
+
isRefreshing = false
|
|
133
|
+
})
|
|
134
|
+
} else {
|
|
135
|
+
// 返回未执行 resolve 的 Promise
|
|
136
|
+
return new Promise(resolve => {
|
|
137
|
+
// 用函数形式将 resolve 存入,等待刷新后再执行
|
|
138
|
+
requests.push(token => {
|
|
139
|
+
config.headers.Authorization = `Bearer ${token}`
|
|
140
|
+
resolve(instance(config))
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Promise.reject(error)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
// 给请求头添加 access_token
|
|
149
|
+
const setHeaderToken = (isNeedToken) => {
|
|
150
|
+
const accessToken = isNeedToken ? getToken() : null
|
|
151
|
+
if (isNeedToken) { // api 请求需要携带 access_token
|
|
152
|
+
if (!accessToken) {
|
|
153
|
+
console.log('不存在 access_token 则跳转回登录页')
|
|
154
|
+
}
|
|
155
|
+
instance.defaults.headers.common.Authorization = `Bearer ${accessToken}`
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 有些 api 并不需要用户授权使用,则无需携带 access_token;默认不携带,需要传则设置第三个参数为 true
|
|
160
|
+
export const get = (url, params = {}, isNeedToken = false) => {
|
|
161
|
+
setHeaderToken(isNeedToken)
|
|
162
|
+
return instance({
|
|
163
|
+
method: 'get',
|
|
164
|
+
url,
|
|
165
|
+
params,
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const post = (url, params = {}, isNeedToken = false) => {
|
|
170
|
+
setHeaderToken(isNeedToken)
|
|
171
|
+
return instance({
|
|
172
|
+
method: 'post',
|
|
173
|
+
url,
|
|
174
|
+
data: params,
|
|
175
|
+
})
|
|
176
|
+
}
|
package/i18n.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
// vve-i18n-cli.config.js
|
|
2
|
+
module.exports = {
|
|
3
|
+
// 工作目录
|
|
4
|
+
cwd: ".",
|
|
5
|
+
// 根目录,国际文本所在的根目录
|
|
6
|
+
rootDir: "src",
|
|
7
|
+
// 默认所有模块,如果有传module参数,就只处理某个模块
|
|
8
|
+
// '**/module-**/**/index.js'
|
|
9
|
+
moduleIndexRules: ["."],
|
|
10
|
+
// 忽略模块
|
|
11
|
+
ignoreModuleIndexRules: [],
|
|
12
|
+
// 匹配含有国际化文本的文件规则
|
|
13
|
+
i18nFileRules: ["**/*.+(vue|js)"],
|
|
14
|
+
// 不匹配含有国际化文本的文件规则
|
|
15
|
+
ignoreI18nFileRules: [],
|
|
16
|
+
// 国际化文本的正则表达式,正则中第一个捕获对象当做国际化文本
|
|
17
|
+
i18nTextRules: [/(?:[\$.])t\([\s\n]*['"](.+?)['"]/g],
|
|
18
|
+
// 模块的国际化的json文件需要被保留下的key,即使这些组件在项目中没有被引用
|
|
19
|
+
// 规则可以是一个字符串,正则,或者是函数
|
|
20
|
+
keepKeyRules: [
|
|
21
|
+
/^G\/+/, // G/开头的会被保留
|
|
22
|
+
],
|
|
23
|
+
// 忽略国际化KEY的规则
|
|
24
|
+
// 规则可以是一个字符串,正则,或者是函数
|
|
25
|
+
ignoreKeyRules: [],
|
|
26
|
+
// 生成的国际化资源包的输出目录
|
|
27
|
+
outDir: "lang",
|
|
28
|
+
// 生成的国际化的语言
|
|
29
|
+
i18nLanguages: [
|
|
30
|
+
"zh", // 中文
|
|
31
|
+
"en", // 英文
|
|
32
|
+
],
|
|
33
|
+
// 配置文件的路径,没有配置,默认路径是在${cwd}/vve-i18n-cli.config.js
|
|
34
|
+
config: undefined,
|
|
35
|
+
// 是否取配置文件
|
|
36
|
+
disableConfigFile: false,
|
|
37
|
+
// 是否翻译
|
|
38
|
+
translate: false,
|
|
39
|
+
// 翻译的基础语言,默认是用中文翻译
|
|
40
|
+
translateFromLang: "zh",
|
|
41
|
+
// 是否强制翻译,即已翻译修改的内容,也重新用翻译生成
|
|
42
|
+
forceTranslate: false,
|
|
43
|
+
// 翻译的语言
|
|
44
|
+
translateLanguage: ["zh", "en"],
|
|
45
|
+
// 非中文使用拼音来来翻译
|
|
46
|
+
translateUsePinYin: false,
|
|
47
|
+
// 模块下${outDir}/index.js文件不存在才拷贝index.js
|
|
48
|
+
copyIndex: false,
|
|
49
|
+
// 是否强制拷贝最新index.js
|
|
50
|
+
forceCopyIndex: false,
|
|
51
|
+
|
|
52
|
+
// 国际化文本包裹相关
|
|
53
|
+
zhWrap: {
|
|
54
|
+
cwd: ".",
|
|
55
|
+
// 根目录,国际文本所在的根目录
|
|
56
|
+
rootDir: ".",
|
|
57
|
+
ignoreI18nFileRules: [],
|
|
58
|
+
i18nFileRules: ["!(node_modules|config|statsvnTmp)/**/*.+(js|vue)"],
|
|
59
|
+
ignorePreReg: [
|
|
60
|
+
/t\s*\([\s\n]*$/,
|
|
61
|
+
/tl\s*\([\s\n]*$/,
|
|
62
|
+
/console\.(?:log|error|warn|info|debug)\s*\(\s*$/,
|
|
63
|
+
/\/\/\s*$/,
|
|
64
|
+
new RegExp("//.+"),
|
|
65
|
+
new RegExp("i18n-disabled.+"),
|
|
66
|
+
],
|
|
67
|
+
ignoreText: ["^[\\u4e00-\\u9fa5a-zA-Z0-9“._=,':;*#!”-]+$"],
|
|
68
|
+
// js相关文件需要引入的国际化文件
|
|
69
|
+
i18nImportForJs: "",
|
|
70
|
+
// js相关文件需要使用国际化方法
|
|
71
|
+
jsI18nFuncName: "$i18n.$t",
|
|
72
|
+
// vue相关文件需要使用的国际化方法
|
|
73
|
+
vueI18nFuncName: "$t",
|
|
74
|
+
},
|
|
75
|
+
zhCheck: {
|
|
76
|
+
cwd: ".",
|
|
77
|
+
// 根目录,国际文本所在的根目录
|
|
78
|
+
rootDir: ".",
|
|
79
|
+
ignoreI18nFileRules: [],
|
|
80
|
+
i18nFileRules: ["!(node_modules|config|statsvnTmp)/**/*.+(vue|js)"],
|
|
81
|
+
// 反引号中需要忽略的文本规则,可以是正则或者字符串
|
|
82
|
+
ignoreTextInQuoteRules: [/t\(/],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 抽取未翻译的词条到excel文件中
|
|
89
|
+
*/
|
|
90
|
+
const map = require("map-stream");
|
|
91
|
+
const path = require("path");
|
|
92
|
+
const vfs = require("vinyl-fs");
|
|
93
|
+
const XLSX = require("xlsx");
|
|
94
|
+
|
|
95
|
+
const ROOT_DIR = path.resolve("./");
|
|
96
|
+
const fileRules = [
|
|
97
|
+
"**/*/i18n/en.json",
|
|
98
|
+
// "**/eweb-setting-planningDeployment/i18n/en.json",
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const writeExcel = (arr, name = "未翻译词条") => {
|
|
102
|
+
const sheet_data = arr.map((v) => {
|
|
103
|
+
return {
|
|
104
|
+
中文: v,
|
|
105
|
+
English: "",
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
const new_sheet = XLSX.utils.json_to_sheet(sheet_data);
|
|
109
|
+
// // 创新一个新的excel对象,就是workbook
|
|
110
|
+
const new_workbook = XLSX.utils.book_new();
|
|
111
|
+
// // 将表的内容写入workbook
|
|
112
|
+
XLSX.utils.book_append_sheet(new_workbook, new_sheet, "sheet1");
|
|
113
|
+
XLSX.writeFile(new_workbook, `${name}.xlsx`);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
function run() {
|
|
117
|
+
const zhList = [];
|
|
118
|
+
console.log("================================>start", ROOT_DIR);
|
|
119
|
+
vfs
|
|
120
|
+
.src(
|
|
121
|
+
fileRules.map((item) => path.resolve(ROOT_DIR, item)),
|
|
122
|
+
{
|
|
123
|
+
ignore: ["node_modules/**/*", "statsvnTmp/**/*"],
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
.pipe(
|
|
127
|
+
map((file, cb) => {
|
|
128
|
+
console.log("处理文件 =========================>", file.path);
|
|
129
|
+
|
|
130
|
+
let fileContent = file.contents.toString();
|
|
131
|
+
fileContent = JSON.parse(fileContent);
|
|
132
|
+
Object.keys(fileContent).map((zh) => {
|
|
133
|
+
if (zh.match(/[\u4E00-\u9FFF]/)) {
|
|
134
|
+
if (zh === fileContent[zh]) {
|
|
135
|
+
// 未翻译
|
|
136
|
+
zhList.push(zh);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
cb();
|
|
141
|
+
})
|
|
142
|
+
)
|
|
143
|
+
.on("end", () => {
|
|
144
|
+
const uniZh = Array.from(new Set(zhList));
|
|
145
|
+
writeExcel(uniZh);
|
|
146
|
+
console.log("未翻译词条数量:", uniZh.length);
|
|
147
|
+
console.log(
|
|
148
|
+
"================================>end",
|
|
149
|
+
"根目录下生成 excle 文件"
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
run();
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 将翻译后的内容替换到en.json文件中
|
|
159
|
+
*/
|
|
160
|
+
const map = require("map-stream");
|
|
161
|
+
const path = require("path");
|
|
162
|
+
const vfs = require("vinyl-fs");
|
|
163
|
+
const fs = require("fs");
|
|
164
|
+
const XLSX = require("xlsx");
|
|
165
|
+
|
|
166
|
+
// const ROOT_DIR = path.resolve("./");
|
|
167
|
+
// const fileRules = ["**/*/i18n/en.json"];
|
|
168
|
+
// 文件名称 默认名称 resource.json
|
|
169
|
+
const fileName = "resource";
|
|
170
|
+
const fileJsonName = fileName + ".json";
|
|
171
|
+
const fileXlsName = fileName + ".xlsx";
|
|
172
|
+
|
|
173
|
+
const excelReader = (exlcePathArray = []) => {
|
|
174
|
+
if (!Array.isArray(exlcePathArray)) {
|
|
175
|
+
exlcePathArray = [exlcePathArray];
|
|
176
|
+
}
|
|
177
|
+
const obj = {};
|
|
178
|
+
for (const i in exlcePathArray) {
|
|
179
|
+
if (Object.hasOwnProperty.call(exlcePathArray, i)) {
|
|
180
|
+
const excleFilePath = exlcePathArray[i];
|
|
181
|
+
console.log("读取excle " + excleFilePath);
|
|
182
|
+
const workbook = XLSX.readFileSync(excleFilePath, {
|
|
183
|
+
type: "binary",
|
|
184
|
+
});
|
|
185
|
+
for (const sheet in workbook.Sheets) {
|
|
186
|
+
const dataArray = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
|
|
187
|
+
obj[sheet] = dataArray;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return obj;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// 如果未找到 resource.json 查找 excel文件
|
|
195
|
+
if (!fs.existsSync(path.resolve(ROOT_DIR, fileJsonName))) {
|
|
196
|
+
// 判断resource.excel是否存在
|
|
197
|
+
if (fs.existsSync(path.resolve(ROOT_DIR, fileXlsName))) {
|
|
198
|
+
let fileObj = excelReader(path.resolve(ROOT_DIR, fileXlsName));
|
|
199
|
+
let dataObj = {};
|
|
200
|
+
if (fileObj.sheet1) {
|
|
201
|
+
// 中文列存在 例子: {"中文":"下载中...","English":"down…"}
|
|
202
|
+
for (let i = 0; i < fileObj.sheet1.length; i++) {
|
|
203
|
+
let itemZhKey = fileObj.sheet1[i]["中文"];
|
|
204
|
+
let itemEnKey = fileObj.sheet1[i]["English"];
|
|
205
|
+
if (itemZhKey && itemEnKey) {
|
|
206
|
+
dataObj[itemZhKey] = itemEnKey;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 获取sheet1的内容
|
|
211
|
+
const data = JSON.stringify(dataObj);
|
|
212
|
+
try {
|
|
213
|
+
fs.writeFileSync(path.resolve(ROOT_DIR, fileJsonName), data);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.log("生成文件 resource.xlsx 异常");
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
console.log("不存在文件 resource.xlsx");
|
|
220
|
+
throw new Error("不存在文件 resource.xlsx");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const originResource = require(path.resolve(ROOT_DIR, fileJsonName));
|
|
225
|
+
let resource = Object.assign({}, originResource);
|
|
226
|
+
Object.keys(originResource).map((key) => {
|
|
227
|
+
resource[`${key}:`] = `${originResource[key]}:`;
|
|
228
|
+
resource[`${key}:`] = `${originResource[key]}:`;
|
|
229
|
+
resource[`${key})`] = `${originResource[key]})`;
|
|
230
|
+
resource[`${key})`] = `${originResource[key]})`;
|
|
231
|
+
resource[`${key} `] = `${originResource[key]} `;
|
|
232
|
+
resource[` ${key}`] = ` ${originResource[key]}`;
|
|
233
|
+
resource[`(${key}`] = `(${originResource[key]}`;
|
|
234
|
+
resource[`(${key}`] = `(${originResource[key]}`;
|
|
235
|
+
resource[` ${key} `] = ` ${originResource[key]} `;
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
function run() {
|
|
239
|
+
console.log("================================>start", ROOT_DIR);
|
|
240
|
+
let failedCount = 0;
|
|
241
|
+
let successCount = 0;
|
|
242
|
+
let failedZhs = [];
|
|
243
|
+
vfs
|
|
244
|
+
.src(
|
|
245
|
+
fileRules.map((item) => path.resolve(ROOT_DIR, item)),
|
|
246
|
+
{
|
|
247
|
+
ignore: ["node_modules/**/*", "statsvnTmp/**/*"],
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
.pipe(
|
|
251
|
+
map((file, cb) => {
|
|
252
|
+
console.log("处理文件 =========================>", file.path);
|
|
253
|
+
|
|
254
|
+
let fileContent = file.contents.toString();
|
|
255
|
+
fileContent = JSON.parse(fileContent);
|
|
256
|
+
let hasChange = false;
|
|
257
|
+
Object.keys(fileContent).map((zh) => {
|
|
258
|
+
if (zh.match(/[\u4E00-\u9FFF]/)) {
|
|
259
|
+
if (zh === fileContent[zh]) {
|
|
260
|
+
// 未翻译
|
|
261
|
+
if (resource[zh] && resource[zh] !== zh) {
|
|
262
|
+
hasChange = true;
|
|
263
|
+
fileContent[zh] = resource[zh];
|
|
264
|
+
successCount++;
|
|
265
|
+
} else {
|
|
266
|
+
failedCount++;
|
|
267
|
+
failedZhs.push(zh);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (hasChange) {
|
|
273
|
+
fs.writeFileSync(
|
|
274
|
+
file.path,
|
|
275
|
+
JSON.stringify(fileContent, " ", 2) + "\n"
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
cb();
|
|
279
|
+
})
|
|
280
|
+
)
|
|
281
|
+
.on("end", () => {
|
|
282
|
+
fs.writeFileSync(
|
|
283
|
+
"unHandle.json",
|
|
284
|
+
JSON.stringify(failedZhs, " ", 2) + "\n"
|
|
285
|
+
);
|
|
286
|
+
console.log("本次翻译成功词条数量:", successCount);
|
|
287
|
+
console.log("还剩余未翻译词条数量:", failedCount);
|
|
288
|
+
console.log("================================>end");
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
run();
|
|
293
|
+
|
|
294
|
+
// 以下为i18n.config.js默认的完整配置,所有属性均为可选,可以根据自身需要修改
|
|
295
|
+
module.exports = {
|
|
296
|
+
input: 'src',
|
|
297
|
+
output: '', // 没有值时表示完成提取后自动覆盖原始文件
|
|
298
|
+
exclude: ['**/node_modules/**/*'], // 排除不需要提取的文件
|
|
299
|
+
localePath: './locales/zh-CN.json', // 中文语言包的存放位置
|
|
300
|
+
localeFileType: 'json', // 设置语言包的文件类型,支持js、json。默认为json
|
|
301
|
+
// rules每个属性对应的是不同后缀文件的处理方式
|
|
302
|
+
rules: {
|
|
303
|
+
js: {
|
|
304
|
+
caller: '', // 自定义this.$t('xxx')中的this。不填则默认没有调用对象
|
|
305
|
+
functionName: 't', // 自定义this.$t('xxx')中的$t
|
|
306
|
+
customizeKey: function (key, currentFilePath) {
|
|
307
|
+
return key
|
|
308
|
+
}, // 自定义this.$t('xxx')中的'xxx'部分的生成规则
|
|
309
|
+
importDeclaration: 'import { t } from "i18n"', // 默认在文件里导入i18n包。不填则默认不导入i18n的包。由于i18n的npm包有很多,用户可根据项目自行修改导入语法
|
|
310
|
+
forceImport: false, // 即使文件没出现中文,也强行插入importDeclaration定义的语句
|
|
311
|
+
},
|
|
312
|
+
// ts,cjs,mjs,jsx,tsx配置方式同上
|
|
313
|
+
ts: {
|
|
314
|
+
caller: '',
|
|
315
|
+
functionName: 't',
|
|
316
|
+
customizeKey: function (key, currentFilePath) {
|
|
317
|
+
return key
|
|
318
|
+
},
|
|
319
|
+
importDeclaration: 'import { t } from "i18n"',
|
|
320
|
+
forceImport: false,
|
|
321
|
+
},
|
|
322
|
+
cjs: {
|
|
323
|
+
caller: '',
|
|
324
|
+
functionName: 't',
|
|
325
|
+
customizeKey: function (key, currentFilePath) {
|
|
326
|
+
return key
|
|
327
|
+
},
|
|
328
|
+
importDeclaration: 'import { t } from "i18n"',
|
|
329
|
+
forceImport: false,
|
|
330
|
+
},
|
|
331
|
+
mjs: {
|
|
332
|
+
caller: '',
|
|
333
|
+
functionName: 't',
|
|
334
|
+
customizeKey: function (key, currentFilePath) {
|
|
335
|
+
return key
|
|
336
|
+
},
|
|
337
|
+
importDeclaration: 'import { t } from "i18n"',
|
|
338
|
+
forceImport: false,
|
|
339
|
+
},
|
|
340
|
+
jsx: {
|
|
341
|
+
caller: '',
|
|
342
|
+
functionName: 't',
|
|
343
|
+
customizeKey: function (key, currentFilePath) {
|
|
344
|
+
return key
|
|
345
|
+
},
|
|
346
|
+
importDeclaration: 'import { t } from "i18n"',
|
|
347
|
+
functionSnippets: '', // react函数组件里,全局加代码片段
|
|
348
|
+
forceImport: false,
|
|
349
|
+
},
|
|
350
|
+
tsx: {
|
|
351
|
+
caller: '',
|
|
352
|
+
functionName: 't',
|
|
353
|
+
customizeKey: function (key, currentFilePath) {
|
|
354
|
+
return key
|
|
355
|
+
},
|
|
356
|
+
importDeclaration: 'import { t } from "i18n"',
|
|
357
|
+
functionSnippets: '',
|
|
358
|
+
forceImport: false,
|
|
359
|
+
},
|
|
360
|
+
vue: {
|
|
361
|
+
caller: 'this',
|
|
362
|
+
functionNameInTemplate: '$t',// vue这里的配置,仅针对vue的template标签里面的内容生效
|
|
363
|
+
functionNameInScript: '$t', // vue这里的配置,仅针对vue的script部分export default里面的内容生效
|
|
364
|
+
customizeKey: function (key, currentFilePath) {
|
|
365
|
+
return key
|
|
366
|
+
},
|
|
367
|
+
importDeclaration: '',
|
|
368
|
+
forceImport: false,
|
|
369
|
+
tagOrder: ['template', 'script', 'style'], // 支持自定义vue文件的标签顺序
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
globalRule: {
|
|
373
|
+
ignoreMethods: [] // 忽略指定函数调用的中文提取。例如想忽略sensor.track('中文')的提取。这里就写['sensor.track']
|
|
374
|
+
},
|
|
375
|
+
// prettier配置,参考https://prettier.io/docs/en/options.html
|
|
376
|
+
prettier: {
|
|
377
|
+
semi: false,
|
|
378
|
+
singleQuote: true,
|
|
379
|
+
},
|
|
380
|
+
skipExtract: false, // 跳过提取中文阶段
|
|
381
|
+
// 以下是和翻译相关的配置,注意搭配使用
|
|
382
|
+
skipTranslate: true, // 跳过翻译语言包阶段。默认不翻译
|
|
383
|
+
locales: [], // 需要翻译的语言包。例如['en', 'zh-CHT'],会自动翻译英文和繁体
|
|
384
|
+
excelPath: './locales.xlsx', // excel存放路径
|
|
385
|
+
exportExcel: false, // 是否导出excel
|
|
386
|
+
// 参数:
|
|
387
|
+
// allKeyValue:已遍历的所有文件的key-value
|
|
388
|
+
// currentFileKeyMap: 当前文件提取到的key-value
|
|
389
|
+
// currentFilePath: 当前遍历的文件路径
|
|
390
|
+
adjustKeyMap(allKeyValue, currentFileKeyMap, currentFilePath) { return allKeyValue }, // 对提取结构进行二次处理
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
// 参数 类型 默认值 描述
|
|
395
|
+
// -i, --input String 'src' 指定待提取的文件目录。
|
|
396
|
+
// -o, --output String '' 输出转换后文件路径。没有值时表示完成提取后自动覆盖原始文件。当有值时,会输出到指定目录
|
|
397
|
+
// -c, --config-file String '' 指定命令行配置文件的所在路径(可以自定义更多功能)
|
|
398
|
+
// --localePath String './locales/zh-CN.json' 指定提取的中文语言包所存放的路径。
|
|
399
|
+
// -v,--verbose Boolean false 控制台打印更多调试信息
|
|
400
|
+
// -h,--help Boolean false 查看指令用法
|
|
401
|
+
// --skip-extract Boolean false 跳过 i18n 转换阶段。
|
|
402
|
+
// --skip-translate Boolean false 跳过中文翻译阶段。
|
|
403
|
+
// --locales Array ['en-US'] 根据中文语言包自动翻译成其他语言。用法例子 --locales en zh-CHT
|
|
404
|
+
// --incremental Boolean false 开启后。支持将文件中提取到中文键值对,追加到原有的中文语言包。
|
|
405
|
+
// --exportExcel Boolean false 开启后。导出所有翻译内容到 excel。 默认导出到当前目录下的 locales.xlsx
|
|
406
|
+
// --excelPath String './locales.xlsx' 指定导出的 excel 路径。
|
package/package.json
CHANGED
|
Binary file
|