Skip to content

Commit

Permalink
fix: update tranlate script
Browse files Browse the repository at this point in the history
  • Loading branch information
阮文涛 committed Oct 17, 2023
1 parent 9a3a19c commit 156b8bc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"autocorrect-node": "^2.8.4",
"feishu-pages": "^0.4.2",
"fs-extra": "^11.1.1",
"glob": "^10.3.10",
"opencc-js": "^1.0.5",
"vitepress": "^1.0.0-rc.20"
Expand Down
25 changes: 19 additions & 6 deletions scripts/cn2hk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Iter *.md in docs/zh-CN/**/*.md and use OpenCC to convert to docs/zh-HK/**/*.md
// Usage: node scripts/cn2hk.js

const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');
const glob = require('glob');
const OpenCC = require('opencc-js');
Expand All @@ -12,18 +12,31 @@ const converter = OpenCC.Converter({ from: 'cn', to: 'hk' });
* Iterator all .md file in docs/zh-CN/ and convert to docs/zh-HK/
*/
const convert = () => {

let content = fs.readFileSync('docs/zh-CN.md', 'utf8');
let newContent = converter(content);
fs.writeFileSync('docs/zh-HK.md', newContent);

let files = glob.sync('docs/zh-CN/**/*.md');

const sourceFolder = 'docs/zh-CN'; // 源文件夹
const destinationFolder = 'docs/zh-HK'; // 目标文件夹
fs.ensureDirSync(destinationFolder);
const files = fs.readdirSync(sourceFolder)
files.forEach((file) => {
const sourcePath = `${sourceFolder}/${file}`;
const destinationPath = `${destinationFolder}/${file}`;
// 复制文件
fs.copySync(sourcePath, destinationPath);
console.log(`复制文件:${file}`);
})
console.log(`所有文件从 ${sourceFolder}${destinationFolder} 复制完成。`);


let filesHK = glob.sync('docs/zh-HK/**/*.md');
filesHK.forEach((file) => {
let content = fs.readFileSync(file, 'utf8');
let newContent = converter(content);
let newFile = file.replace('zh-CN', 'zh-HK');
let folder = path.dirname(newFile);
fs.mkdirSync(folder, { recursive: true });
fs.writeFileSync(newFile, newContent);
fs.writeFileSync(file, newContent, 'utf8');
});
};

Expand Down
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,15 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

fs-extra@^11.1.1:
version "11.1.1"
resolved "https://registry.npmmirror.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
Expand All @@ -812,6 +821,11 @@ glob@^10.3.10:
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
path-scurry "^1.10.1"

graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.11"
resolved "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==

html-encoding-sniffer@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz#2cb1a8cf0db52414776e5b2a7a04d5dd98158de9"
Expand Down Expand Up @@ -908,6 +922,15 @@ jsonc-parser@^3.2.0:
resolved "https://registry.npmmirror.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.npmmirror.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.npmmirror.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
Expand Down Expand Up @@ -1195,6 +1218,11 @@ universalify@^0.2.0:
resolved "https://registry.npmmirror.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

url-parse@^1.5.3:
version "1.5.10"
resolved "https://registry.npmmirror.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
Expand Down

0 comments on commit 156b8bc

Please sign in to comment.