epub-translator 0.0.2__py3-none-any.whl → 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,7 @@ class _Translator:
63
63
  try:
64
64
  temp_dir = _clean_path(working_path / "temp")
65
65
  temp_dir.mkdir(parents=True, exist_ok=True)
66
+ cache_path = working_path / "cache"
66
67
 
67
68
  context = ZipContext(
68
69
  epub_path=Path(source_path),
@@ -70,11 +71,12 @@ class _Translator:
70
71
  )
71
72
  context.replace_ncx(lambda texts: self._translate_ncx(
72
73
  texts=texts,
74
+ cache_path=cache_path,
73
75
  report_progress=lambda p: self._report_progress(p * 0.1)),
74
76
  )
75
77
  self._translate_spine(
76
78
  context=context,
77
- working_path=working_path,
79
+ cache_path=cache_path,
78
80
  report_progress=lambda p: self._report_progress(0.1 + p * 0.8),
79
81
  )
80
82
  context.archive(translated_path)
@@ -84,10 +86,10 @@ class _Translator:
84
86
  if is_temp_workspace:
85
87
  rmtree(working_path, ignore_errors=True)
86
88
 
87
- def _translate_ncx(self, texts: list[str], report_progress: ProgressReporter) -> list[str]:
89
+ def _translate_ncx(self, texts: list[str], cache_path: Path, report_progress: ProgressReporter) -> list[str]:
88
90
  return list(_translate(
89
91
  llm=self._llm,
90
- cache_path=None,
92
+ cache_path=cache_path,
91
93
  max_chunk_tokens_count=self._max_chunk_tokens_count,
92
94
  max_threads_count=1,
93
95
  target_language=self._target_language,
@@ -103,7 +105,7 @@ class _Translator:
103
105
  ),
104
106
  ))
105
107
 
106
- def _translate_spine(self, context: ZipContext, working_path: Path, report_progress: ProgressReporter):
108
+ def _translate_spine(self, context: ZipContext, cache_path: Path, report_progress: ProgressReporter):
107
109
  spine_paths_iter = iter(list(context.search_spine_paths()))
108
110
  spine_file: HTMLFile | None = None
109
111
  translated_texts: list[str] = []
@@ -112,7 +114,7 @@ class _Translator:
112
114
  for translated_text in _translate(
113
115
  llm=self._llm,
114
116
  gen_fragments_iter=lambda: _gen_fragments(context),
115
- cache_path=working_path / "cache",
117
+ cache_path=cache_path,
116
118
  max_chunk_tokens_count=self._max_chunk_tokens_count,
117
119
  max_threads_count=self._max_threads_count,
118
120
  target_language=self._target_language,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: epub-translator
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Translate the epub book using LLM. The translated book will retain the original text and list the translated text side by side with the original text.
5
5
  License: MIT
6
6
  Keywords: epub,llm,translation,translator
@@ -21,7 +21,7 @@ epub_translator/translation/store.py,sha256=1FmksPAUj0mt3tN8Jdb_L1ovaI1p_5OhTWgx
21
21
  epub_translator/translation/translation.py,sha256=_qiw6s_z_Tv4VmIP1U-_YhDYNiKEDNfigHIIGKa41fU,5734
22
22
  epub_translator/translation/types.py,sha256=vDW5bVqYwngW_YUgf0SgfZ5zIFWUxcbBGO1U9Dsxc0o,499
23
23
  epub_translator/translation/utils.py,sha256=G6Gqq6mot3lgFA-jqUD0UqtDS0GC1wrb9DnK7rTxJNs,223
24
- epub_translator/translator.py,sha256=k4YmmCh0W5Zyz8CZJTXO86SShuwg8ydm38CuIB_mlTw,5253
24
+ epub_translator/translator.py,sha256=oh7PdCijUSGU6f72hzc6doJdMWnAqg6zHRFIj3aeTjc,5332
25
25
  epub_translator/xml/__init__.py,sha256=o2_qwUYU_MUcyfmfKkiOQ-cKUQyl4PiRL8YHVzCTAZU,106
26
26
  epub_translator/xml/decoder.py,sha256=UlqgmEKQDzxt3lvBeNGHgZP6jznmnq_1HLJuAe5X0C4,2181
27
27
  epub_translator/xml/encoder.py,sha256=p4A7GRSOM2i0WOh1lLtEdTTg2gXSQrxDdzMgUqbiV18,2428
@@ -30,7 +30,7 @@ epub_translator/xml/tag.py,sha256=QLZImF0PtYyiASI7swrB8DL_qUwcYpU6cL68jEXDnvg,23
30
30
  epub_translator/xml/transform.py,sha256=vS_a4d_o2Qqf9B6k2CovQVLUknp6TyUi3FyLOu21Vio,1126
31
31
  epub_translator/xml/utils.py,sha256=KDNGWHwaIiFKS27sjZF0e-bBSjeTxzceae_aeuj4wzI,384
32
32
  epub_translator/zip_context.py,sha256=7_05kycmADb4-vxHkw_DX__vkKOxT4zo9pr2a8F4L_U,2409
33
- epub_translator-0.0.2.dist-info/LICENSE,sha256=5RF32sL3LtMOJIErdDKp1ZEYPGXS8WPpsiSz_jMBnGI,1066
34
- epub_translator-0.0.2.dist-info/METADATA,sha256=L9JKe5KAg-_naR8vLIGR043p1m_LvbGsvlSTqGzVGaw,2342
35
- epub_translator-0.0.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
36
- epub_translator-0.0.2.dist-info/RECORD,,
33
+ epub_translator-0.0.3.dist-info/LICENSE,sha256=5RF32sL3LtMOJIErdDKp1ZEYPGXS8WPpsiSz_jMBnGI,1066
34
+ epub_translator-0.0.3.dist-info/METADATA,sha256=HuD7ogzPi96e8ZKjAJyTARhSeR4xmu3vZt0Q3Vmg0Hk,2342
35
+ epub_translator-0.0.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
36
+ epub_translator-0.0.3.dist-info/RECORD,,