Skip to content

Commit

Permalink
fix: translate list
Browse files Browse the repository at this point in the history
  • Loading branch information
Byaidu committed Dec 13, 2024
1 parent b63ff57 commit c6c0b4f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pdf2zh example.pdf -t 1
from pdf2zh import translate, translate_stream
params = {"lang_in": "en", "lang_out": "zh", "service": "google", "thread": 4}
doc_mono, doc_dual = translate(files=["example.pdf"], **params)
file_mono, file_dual = translate(files=["example.pdf"], **params)[0]
with open("example.pdf", "rb") as f:
stream_mono, stream_dual = translate_stream(stream=f.read(), **params)
```
Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pdf2zh example.pdf -t 1
from pdf2zh import translate, translate_stream
params = {"lang_in": "en", "lang_out": "zh", "service": "google", "thread": 4}
doc_mono, doc_dual = translate(files=["example.pdf"], **params)
file_mono, file_dual = translate(files=["example.pdf"], **params)[0]
with open("example.pdf", "rb") as f:
stream_mono, stream_dual = translate_stream(stream=f.read(), **params)
```
Expand Down
5 changes: 4 additions & 1 deletion pdf2zh/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def translate(
print(f" {file}", file=sys.stderr)
raise PDFValueError("Some files do not exist.")

result_files = []

for file in files:
if file is str and (file.startswith("http://") or file.startswith("https://")):
print("Online files detected, downloading...")
Expand Down Expand Up @@ -280,5 +282,6 @@ def translate(
doc_dual = open(file_dual, "wb")
doc_mono.write(s_mono)
doc_dual.write(s_dual)
result_files.append((str(file_mono), str(file_dual)))

return str(file_mono), str(file_dual)
return result_files

0 comments on commit c6c0b4f

Please sign in to comment.