增加翻译文件夹选项,设定保存路径,在路径下面创建momo和dual放翻译好的文章
benjohn18 opened this issue · comments
在什么场景下,需要你请求的功能?
目前网页端需要人工手动一个个选择文献,手工操作。
用代码调用pdf2zh的话,要用脚本首先读取文件夹路径的pdf然后进行翻译。
希望官方能够增加整个文件夹路径下面所有pdf文件都进行翻译,保存到指定文献。
解决方案
目前这是我的解决方法,希望官方能够提供更好的文件夹翻译整合方案。 让其他一些不懂代码的人,也能够批量翻译文献。
file_list = os.listdir(dir_path)
file_list = [file for file in file_list if file.endswith('.pdf')]
for file in file_list:
file_path = os.path.join(dir_path, file) # 获取文件的完整路径
# 执行命令cd
try:
subprocess.run(['pdf2zh', file_path, '-o', result_dir, '-s', 'silicon', '-t',
'4'], check=True)
except subprocess.CalledProcessError as e:
print(f"Error converting {file}: {e}")
其他内容
No response