mirror of
https://github.com/one-among-us/data.git
synced 2024-12-05 09:26:50 +08:00
[+] Scripts for translate
This commit is contained in:
parent
daa5ab649f
commit
3e7066cce4
@ -12,7 +12,8 @@
|
||||
"build": "node --loader ts-node/esm/transpile-only scripts/build.ts",
|
||||
"build-preview": "yarn build && scripts/preview.sh",
|
||||
"serve": "http-server --cors='*' dist",
|
||||
"preview": "yarn build-preview && yarn serve"
|
||||
"preview": "yarn build-preview && yarn serve",
|
||||
"translate": "node --loader ts-node/esm/transpile-only scripts/translate.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@andreekeberg/imagedata": "^1.0.2",
|
||||
@ -20,10 +21,12 @@
|
||||
"@swc/core": "^1.3.17",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/node": "^20",
|
||||
"args-parser": "^1.3.0",
|
||||
"autocorrect-node": "^2.5.5",
|
||||
"blurhash": "^2.0.5",
|
||||
"esbuild": "^0.18.10",
|
||||
"fs-extra": "^11.1.0",
|
||||
"google-translate-api-x": "^10.7.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"katex": "^0.16.10",
|
||||
"markdown-yaml-metadata-parser": "^3.0.0",
|
||||
|
38
scripts/translate.ts
Normal file
38
scripts/translate.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import url from "url";
|
||||
import path from "path";
|
||||
import fs from "fs-extra";
|
||||
import Parse from 'args-parser'
|
||||
import translate from "google-translate-api-x";
|
||||
|
||||
const PEOPLE_DIR = 'people'
|
||||
|
||||
const projectRoot = path.dirname(path.dirname(url.fileURLToPath(import.meta.url)));
|
||||
const peopleDir = path.join(projectRoot, PEOPLE_DIR);
|
||||
|
||||
type lang = 'zh-CN' | 'en' | 'zh-TW'
|
||||
|
||||
const m = {
|
||||
'zh-CN': '',
|
||||
'en': '.en',
|
||||
'zh-TW': '.zh_hant'
|
||||
}
|
||||
|
||||
const args = Parse(process.argv)
|
||||
|
||||
console.log(args)
|
||||
|
||||
async function translateFile(id: string, from: lang, to: lang) {
|
||||
const md = fs.readFileSync(path.join(peopleDir, id, `page${m[from]}.md`)).toString()
|
||||
const td = await translate(md, {
|
||||
from: from,
|
||||
to: to,
|
||||
autoCorrect: true
|
||||
})
|
||||
fs.writeFileSync(path.join(peopleDir, id, `page${m[to]}.md`), td.text)
|
||||
}
|
||||
|
||||
if (!(args['from'] && args['to'] && args['id'])) {
|
||||
throw new Error('args should be --from=from --to=to --id=id')
|
||||
}
|
||||
|
||||
await translateFile(args['id'], args['from'], args['to'])
|
10
yarn.lock
10
yarn.lock
@ -777,6 +777,11 @@ argparse@^2.0.1:
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
|
||||
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
|
||||
|
||||
args-parser@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/args-parser/-/args-parser-1.3.0.tgz#c52280e7a454df00ff35bc37ab7cfb543f28d304"
|
||||
integrity sha512-If3Zi4BSjlQIJ9fgAhSiKi0oJtgMzSqh0H4wvl7XSeO16FKx7QqaHld8lZeEajPX7y1C5qKKeNgyrfyvmjmjUQ==
|
||||
|
||||
astring@^1.8.0:
|
||||
version "1.8.6"
|
||||
resolved "https://registry.yarnpkg.com/astring/-/astring-1.8.6.tgz#2c9c157cf1739d67561c56ba896e6948f6b93731"
|
||||
@ -1157,6 +1162,11 @@ global@~4.4.0:
|
||||
min-document "^2.19.0"
|
||||
process "^0.11.10"
|
||||
|
||||
google-translate-api-x@^10.7.1:
|
||||
version "10.7.1"
|
||||
resolved "https://registry.yarnpkg.com/google-translate-api-x/-/google-translate-api-x-10.7.1.tgz#e82215048250385ed97195888eaa1b497aa6e3ae"
|
||||
integrity sha512-OdZDS6jRWzn1woOk62aOKQ5OyVaJSA+eyc6CktOWxo36IWfstOjwG/dkvnGl3Z2Sbpmk1A+jc2WwrBiRjqaY2A==
|
||||
|
||||
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
|
||||
version "4.2.11"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
|
||||
|
Loading…
Reference in New Issue
Block a user