Bladeren bron

fix: translate list

Byaidu 11 maanden geleden
bovenliggende
commit
c6c0b4fa8f
3 gewijzigde bestanden met toevoegingen van 6 en 3 verwijderingen
  1. 1 1
      README.md
  2. 1 1
      README_zh-CN.md
  3. 4 1
      pdf2zh/high_level.py

+ 1 - 1
README.md

@@ -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)
 ```

+ 1 - 1
README_zh-CN.md

@@ -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)
 ```

+ 4 - 1
pdf2zh/high_level.py

@@ -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...")
@@ -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