Skip to content

Instantly share code, notes, and snippets.

@syrinka
Last active September 29, 2023 13:12
Show Gist options
  • Save syrinka/438cb62a58d0addd309019f4d929700b to your computer and use it in GitHub Desktop.
Save syrinka/438cb62a58d0addd309019f4d929700b to your computer and use it in GitHub Desktop.
A crude gist to convert zh-hans to zh-hant in batch
import zhconv
import sys
import os
from pathlib import Path
src = Path(sys.argv[1]).absolute()
dst = Path(sys.argv[2]).absolute()
for cur, dirs, files in os.walk(src):
for file in files:
file = Path(cur, file)
newfile = dst / file.relative_to(src)
newfile.parent.mkdir(exist_ok=True, parents=True)
newfile.write_text(
zhconv.convert(
file.read_text(encoding='utf-8'), 'zh-hant'
),
encoding='utf-8'
)
# rimworld s-t converter
import os
from pathlib import Path
from zhconv import convert
src = 'ChineseSimplified'
dst = 'ChineseTraditional'
kw = dict(encoding='utf-8')
for c, ds, fs in os.walk(src):
for f in fs:
old = Path(c, f)
new = dst / old.relative_to(src)
new.parent.mkdir(exist_ok=True, parents=True)
new.write_text(convert(old.read_text(**kw), 'zh-hant'), **kw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment