td-octopus 0.1.4 → 0.1.5
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/cmds/download.js +22 -18
- package/package.json +2 -2
- package/src/download/index.js +8 -2
package/cmds/download.js
CHANGED
|
@@ -15,35 +15,39 @@ exports.handler = async (argv) => {
|
|
|
15
15
|
const config = getProjectConfig();
|
|
16
16
|
const otpPath = path.resolve(process.cwd(), config.otpDir);
|
|
17
17
|
const url = config.downloadUrl
|
|
18
|
-
let
|
|
18
|
+
let distLangs = config.distLangs
|
|
19
|
+
// let lang = "en-US"
|
|
19
20
|
if (!url) {
|
|
20
21
|
console.log(`请配置${OCTOPUS_CONFIG_FILE}里面的downloadUrl`)
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
24
|
+
|
|
23
25
|
axios.get(url)
|
|
24
26
|
.then((response) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
distLangs?.map(lang => {
|
|
28
|
+
// 给目录和翻译文件item赋值
|
|
29
|
+
const jsonData = response?.data?.data?.jsonData?.children || [];
|
|
30
|
+
// 将嵌套的 JSON 数据转换为 node-xlsx 格式
|
|
31
|
+
const xlsxData = convertJsonToXlsx(jsonData, lang);
|
|
32
|
+
|
|
33
|
+
const options = {
|
|
34
|
+
'!cols': [{ wpx: 100 }, { wpx: 100 }, { wpx: 100 }, { wpx: 100 }]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const worksheet = XLSX.utils.aoa_to_sheet(xlsxData[0]?.data);
|
|
38
|
+
worksheet['!cols'] = options['!cols'];
|
|
39
|
+
|
|
40
|
+
const workbook = XLSX.utils.book_new();
|
|
41
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
|
42
|
+
XLSX.writeFile(workbook, `${otpPath}/${lang}/translate_${lang}.xls`);
|
|
43
|
+
console.log(`下载成功`)
|
|
44
|
+
})
|
|
42
45
|
})
|
|
43
46
|
.catch((error) => {
|
|
44
47
|
console.error(`Error: ${error.message}`);
|
|
45
48
|
console.error(`请正确配置downloadUrl里的code与projectId`);
|
|
46
49
|
|
|
47
50
|
});
|
|
51
|
+
|
|
48
52
|
}
|
|
49
53
|
|
package/package.json
CHANGED
package/src/download/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
const convertJsonToXlsx = (data,
|
|
1
|
+
const convertJsonToXlsx = (data, lang) => {
|
|
2
|
+
let langMap = {
|
|
3
|
+
"zh-TW": "繁体中文",
|
|
4
|
+
"en-US": "英文",
|
|
5
|
+
"fr-FR": "法语",
|
|
6
|
+
}
|
|
7
|
+
let module = ["中文"]
|
|
8
|
+
module.push(langMap[lang])
|
|
2
9
|
|
|
3
|
-
let module = ["中文", "英文"]
|
|
4
10
|
const result = [{ name: 'Sheet1', data: [['需要翻译的字段'].concat(["中文", "人工翻译"])] }];
|
|
5
11
|
|
|
6
12
|
const traverse = (node) => {
|