You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
973 B
40 lines
973 B
from sys import argv
|
|
from os import makedirs
|
|
from os.path import exists
|
|
from chardet import detect
|
|
from tkinter import filedialog, Tk
|
|
from zhconv import convert
|
|
|
|
print("繁体字转简体字",flush=True)
|
|
file_list = argv[1:]
|
|
|
|
if file_list == []:
|
|
root = Tk()
|
|
root.withdraw()
|
|
file_list = filedialog.askopenfilenames()
|
|
|
|
for file_name in file_list:
|
|
name =file_name.split("/")[-1]
|
|
print("转换:"+name+"...", end="", flush=True)
|
|
# 判断文件类型
|
|
with open(file_name, 'rb') as f:
|
|
file_type = detect(f.read())['encoding']
|
|
|
|
# 读取文件
|
|
with open(file_name,"r", encoding=file_type) as f:
|
|
data = f.read()
|
|
|
|
#修改编码
|
|
data = convert(data, "zh-hans")
|
|
|
|
#写入文件
|
|
dir_name = "Translated"
|
|
if not exists(dir_name):
|
|
makedirs(dir_name)
|
|
with open(dir_name+"/"+name, "w", encoding=file_type) as f:
|
|
f.write(data)
|
|
print("Done")
|
|
|
|
|
|
print("请按回车键或直接关闭窗口")
|
|
input()
|