BabelDOC 0.3.51__tar.gz → 0.3.53__tar.gz

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.
Files changed (109) hide show
  1. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/docs.yml +1 -1
  2. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/publish-to-pypi.yml +1 -1
  3. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/test.yml +1 -1
  4. {babeldoc-0.3.51 → babeldoc-0.3.53}/PKG-INFO +3 -3
  5. {babeldoc-0.3.51 → babeldoc-0.3.53}/README.md +2 -2
  6. babeldoc-0.3.53/babeldoc/__init__.py +1 -0
  7. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/const.py +1 -1
  8. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/il_translator.py +6 -0
  9. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/il_translator_llm_only.py +50 -61
  10. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/high_level.py +3 -0
  11. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/main.py +1 -1
  12. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/tools/italic_assistance.py +11 -0
  13. babeldoc-0.3.53/docs/supported_languages.md +171 -0
  14. {babeldoc-0.3.51 → babeldoc-0.3.53}/mkdocs.yml +1 -1
  15. {babeldoc-0.3.51 → babeldoc-0.3.53}/pyproject.toml +2 -2
  16. {babeldoc-0.3.51 → babeldoc-0.3.53}/uv.lock +1 -1
  17. babeldoc-0.3.51/babeldoc/__init__.py +0 -1
  18. babeldoc-0.3.51/docs/supported_languages.md +0 -168
  19. {babeldoc-0.3.51 → babeldoc-0.3.53}/.cursorignore +0 -0
  20. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
  21. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
  22. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/PULL_REQUEST_TEMPLATE/pr_form.yml +0 -0
  23. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  24. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/dependabot.yml +0 -0
  25. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/labels.yml +0 -0
  26. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/release-drafter.yml +0 -0
  27. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/codeql.yml +0 -0
  28. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/labeler.yml +0 -0
  29. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/lint.yml +0 -0
  30. {babeldoc-0.3.51 → babeldoc-0.3.53}/.github/workflows/pr-lint.yml +0 -0
  31. {babeldoc-0.3.51 → babeldoc-0.3.53}/.gitignore +0 -0
  32. {babeldoc-0.3.51 → babeldoc-0.3.53}/.pre-commit-config.yaml +0 -0
  33. {babeldoc-0.3.51 → babeldoc-0.3.53}/LICENSE +0 -0
  34. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/assets/assets.py +0 -0
  35. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/assets/embedding_assets_metadata.py +0 -0
  36. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/asynchronize/__init__.py +0 -0
  37. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/converter.py +0 -0
  38. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/__init__.py +0 -0
  39. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/babeldoc_exception/BabelDOCException.py +0 -0
  40. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/backend/__init__.py +0 -0
  41. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/backend/pdf_creater.py +0 -0
  42. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/frontend/__init__.py +0 -0
  43. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/frontend/il_creater.py +0 -0
  44. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/il_version_1.py +0 -0
  45. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/il_version_1.rnc +0 -0
  46. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/il_version_1.rng +0 -0
  47. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/il_version_1.xsd +0 -0
  48. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/__init__.py +0 -0
  49. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/add_debug_information.py +0 -0
  50. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/detect_scanned_file.py +0 -0
  51. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/layout_parser.py +0 -0
  52. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/paragraph_finder.py +0 -0
  53. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/remove_descent.py +0 -0
  54. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/styles_and_formulas.py +0 -0
  55. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/table_parser.py +0 -0
  56. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/midend/typesetting.py +0 -0
  57. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/translator/__init__.py +0 -0
  58. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/translator/cache.py +0 -0
  59. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/translator/translator.py +0 -0
  60. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/atomic_integer.py +0 -0
  61. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/fontmap.py +0 -0
  62. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/layout_helper.py +0 -0
  63. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/mupdf_helper.py +0 -0
  64. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/paragraph_helper.py +0 -0
  65. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/priority_thread_pool_executor.py +0 -0
  66. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/style_helper.py +0 -0
  67. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/utils/zstd_helper.py +0 -0
  68. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/document_il/xml_converter.py +0 -0
  69. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/docvision/README.md +0 -0
  70. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/docvision/__init__.py +0 -0
  71. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/docvision/doclayout.py +0 -0
  72. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/docvision/rpc_doclayout.py +0 -0
  73. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/docvision/table_detection/rapidocr.py +0 -0
  74. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/format/office/__init__.py +0 -0
  75. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/pdfinterp.py +0 -0
  76. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/progress_monitor.py +0 -0
  77. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/result_merger.py +0 -0
  78. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/split_manager.py +0 -0
  79. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/tools/generate_font_metadata.py +0 -0
  80. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/tools/italic_recognize_tool.py +0 -0
  81. {babeldoc-0.3.51 → babeldoc-0.3.53}/babeldoc/translation_config.py +0 -0
  82. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/CODE_OF_CONDUCT.md +0 -0
  83. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/CONTRIBUTING.md +0 -0
  84. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/CONTRIBUTOR_REWARD.md +0 -0
  85. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
  86. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
  87. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
  88. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
  89. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
  90. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/README.md +0 -0
  91. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
  92. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
  93. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/README.md +0 -0
  94. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/deploy.sh +0 -0
  95. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-banner.png +0 -0
  96. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.png +0 -0
  97. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.svg +0 -0
  98. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-big-logo-with-transparent-background.png +0 -0
  99. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-big-logo-with-transparent-background.svg +0 -0
  100. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-big-logo.png +0 -0
  101. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-contributor_reward_example.png +0 -0
  102. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-preview.gif +0 -0
  103. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-small-logo-with-transparent-background.png +0 -0
  104. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-small-logo-with-transparent-background.svg +0 -0
  105. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/images/babeldoc-small-logo.png +0 -0
  106. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/index.md +0 -0
  107. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/intro-to-pdf-object.md +0 -0
  108. {babeldoc-0.3.51 → babeldoc-0.3.53}/docs/requirements.txt +0 -0
  109. {babeldoc-0.3.51 → babeldoc-0.3.53}/tests/test_translation_config.py +0 -0
@@ -17,7 +17,7 @@ jobs:
17
17
  git config user.name github-actions[bot]
18
18
  git config user.email 41898282+github-actions[bot]@users.noreply.github.com
19
19
  - name: Setup uv with Python 3.12
20
- uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
20
+ uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0
21
21
  with:
22
22
  python-version: "3.12"
23
23
  enable-cache: true
@@ -35,7 +35,7 @@ jobs:
35
35
  token: ${{ secrets.GITHUB_TOKEN }}
36
36
 
37
37
  - name: Setup uv with Python 3.12
38
- uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
38
+ uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0
39
39
  with:
40
40
  python-version: "3.12"
41
41
  enable-cache: true
@@ -28,7 +28,7 @@ jobs:
28
28
  path: ~/.cache/babeldoc
29
29
  key: babeldoc-assets-${{ hashFiles('babeldoc/assets/embedding_assets_metadata.py') }}
30
30
  - name: Setup uv with Python ${{ matrix.python-version }}
31
- uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
31
+ uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb # v6.1.0
32
32
  with:
33
33
  python-version: ${{ matrix.python-version }}
34
34
  enable-cache: true
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: BabelDOC
3
- Version: 0.3.51
3
+ Version: 0.3.53
4
4
  Summary: Yet Another Document Translator
5
5
  Project-URL: Homepage, https://github.com/funstory-ai/BabelDOC
6
6
  Project-URL: Issues, https://github.com/funstory-ai/BabelDOC/issues
@@ -127,10 +127,10 @@ babeldoc --help
127
127
  3. Use the `babeldoc` command. For example:
128
128
 
129
129
  ```bash
130
- babeldoc --bing --files example.pdf
130
+ babeldoc --openai --openai-model "gpt-4o-mini" --openai-base-url "https://api.openai.com/v1" --openai-api-key "your-api-key-here" --files example.pdf
131
131
 
132
132
  # multiple files
133
- babeldoc --bing --files example1.pdf --files example2.pdf
133
+ babeldoc --openai --openai-model "gpt-4o-mini" --openai-base-url "https://api.openai.com/v1" --openai-api-key "your-api-key-here" --files example1.pdf --files example2.pdf
134
134
  ```
135
135
 
136
136
  ### Install from Source
@@ -78,10 +78,10 @@ babeldoc --help
78
78
  3. Use the `babeldoc` command. For example:
79
79
 
80
80
  ```bash
81
- babeldoc --bing --files example.pdf
81
+ babeldoc --openai --openai-model "gpt-4o-mini" --openai-base-url "https://api.openai.com/v1" --openai-api-key "your-api-key-here" --files example.pdf
82
82
 
83
83
  # multiple files
84
- babeldoc --bing --files example1.pdf --files example2.pdf
84
+ babeldoc --openai --openai-model "gpt-4o-mini" --openai-base-url "https://api.openai.com/v1" --openai-api-key "your-api-key-here" --files example1.pdf --files example2.pdf
85
85
  ```
86
86
 
87
87
  ### Install from Source
@@ -0,0 +1 @@
1
+ __version__ = "0.3.53"
@@ -3,7 +3,7 @@ import shutil
3
3
  import subprocess
4
4
  from pathlib import Path
5
5
 
6
- __version__ = "0.3.51"
6
+ __version__ = "0.3.53"
7
7
 
8
8
  CACHE_FOLDER = Path.home() / ".cache" / "babeldoc"
9
9
 
@@ -21,6 +21,7 @@ from babeldoc.document_il import PdfStyle
21
21
  from babeldoc.document_il.translator.translator import BaseTranslator
22
22
  from babeldoc.document_il.utils.fontmap import FontMapper
23
23
  from babeldoc.document_il.utils.layout_helper import get_char_unicode_string
24
+ from babeldoc.document_il.utils.layout_helper import get_paragraph_unicode
24
25
  from babeldoc.document_il.utils.layout_helper import is_same_style
25
26
  from babeldoc.document_il.utils.layout_helper import is_same_style_except_font
26
27
  from babeldoc.document_il.utils.layout_helper import is_same_style_except_size
@@ -208,6 +209,8 @@ class ILTranslator:
208
209
  except NotImplementedError:
209
210
  self.support_llm_translate = False
210
211
 
212
+ self.use_as_fallback = False
213
+
211
214
  def calc_token_count(self, text: str) -> int:
212
215
  try:
213
216
  return len(self.tokenizer.encode(text, disallowed_special=()))
@@ -851,6 +854,9 @@ Now, please carefully read the following text to be translated and directly outp
851
854
  self.translation_config.raise_if_cancelled()
852
855
  with PbarContext(pbar):
853
856
  try:
857
+ if self.use_as_fallback:
858
+ # il translator llm only modifies unicode in some situations
859
+ paragraph.unicode = get_paragraph_unicode(paragraph)
854
860
  # Pre-translation processing
855
861
  text, translate_input = self.pre_translate_paragraph(
856
862
  paragraph, tracker, page_font_map, xobj_font_map
@@ -61,7 +61,7 @@ class ILTranslatorLLMOnly:
61
61
  translation_config=translation_config,
62
62
  tokenizer=self.tokenizer,
63
63
  )
64
-
64
+ self.il_translator.use_as_fallback = True
65
65
  try:
66
66
  self.translate_engine.do_llm_translate(None)
67
67
  except NotImplementedError as e:
@@ -122,10 +122,10 @@ class ILTranslatorLLMOnly:
122
122
  total,
123
123
  ) as pbar:
124
124
  with PriorityThreadPoolExecutor(
125
- max_workers=self.translation_config.qps,
125
+ max_workers=self.translation_config.qps * 5,
126
126
  ) as executor2:
127
127
  with PriorityThreadPoolExecutor(
128
- max_workers=self.translation_config.qps,
128
+ max_workers=self.translation_config.qps * 5,
129
129
  ) as executor:
130
130
  for page in docs.page:
131
131
  self.process_page(
@@ -281,55 +281,72 @@ class ILTranslatorLLMOnly:
281
281
  else:
282
282
  llm_prompt_parts.append(
283
283
  f"You are a professional and reliable machine translation engine responsible for translating the input text into {self.translation_config.lang_out}."
284
+ "When translating, strictly follow the instructions below to ensure translation quality and preserve all formatting, tags, and placeholders:\n"
285
+ )
286
+
287
+ # 2. ##Contextual Hints for Better Translation
288
+ other_hints = []
289
+ hint_idx = 1 # Start with 1 for 1-based indexing
290
+ if title_paragraph:
291
+ other_hints.append(
292
+ f"{hint_idx}. First title in full text: {title_paragraph.unicode}"
284
293
  )
294
+ hint_idx += 1
295
+
296
+ if local_title_paragraph:
297
+ is_different_from_global = True
298
+ if title_paragraph:
299
+ if local_title_paragraph.debug_id == title_paragraph.debug_id:
300
+ is_different_from_global = False
301
+
302
+ if is_different_from_global:
303
+ other_hints.append(
304
+ f"{hint_idx}. Most similar section title: {local_title_paragraph.unicode}"
305
+ )
306
+ # hint_idx += 1 # No increment needed if it's the last possible hint of this type
307
+
308
+ if other_hints:
309
+ llm_prompt_parts.append("\n## Contextual Hints for Better Translation")
310
+ llm_prompt_parts.extend(other_hints)
285
311
 
286
- # 2. ##rules
287
- llm_prompt_parts.append("\n##rules")
288
- # Dynamically get placeholder examples
289
- rich_text_left_placeholder = (
290
- self.translate_engine.get_rich_text_left_placeholder(1)
312
+ # 3. ## Strict Rules:
313
+ llm_prompt_parts.append("\n## Strict Rules:")
314
+ llm_prompt_parts.append(
315
+ "1. Do NOT translate or alter any of the following elements:"
291
316
  )
292
- if isinstance(rich_text_left_placeholder, tuple):
293
- rich_text_left_placeholder = rich_text_left_placeholder[0]
294
- rich_text_right_placeholder = (
295
- self.translate_engine.get_rich_text_right_placeholder(2)
317
+ llm_prompt_parts.append(
318
+ " Style or HTML-like tags: e.g., <style id='1'>...</style>, <b>...</b>, <i>...</i>, <code>...</code>, etc."
296
319
  )
297
- if isinstance(rich_text_right_placeholder, tuple):
298
- rich_text_right_placeholder = rich_text_right_placeholder[0]
299
- formula_placeholder = self.translate_engine.get_formular_placeholder(3)
300
- if isinstance(formula_placeholder, tuple):
301
- formula_placeholder = formula_placeholder[0]
302
-
303
320
  llm_prompt_parts.append(
304
- f'1. Do not translate style tags, such as "{rich_text_left_placeholder}xxx{rich_text_right_placeholder}"'
321
+ " Formula or variable placeholders enclosed in curly braces: e.g., {v3}, {equation_1}, {name}, etc."
305
322
  )
306
323
  llm_prompt_parts.append(
307
- f'2. Do not translate formula placeholders, such as "{formula_placeholder}". The system will automatically replace the placeholders with the corresponding formulas.'
324
+ " Any other placeholders like [[...]], %%...%%, %s, %d, etc."
308
325
  )
309
326
  llm_prompt_parts.append(
310
- "3. If there is no need to translate (such as proper nouns, codes, etc.), then return the original text."
327
+ "2. Preserve the exact structure, position, and content of the above elements — do not modify spacing, punctuation, or formatting."
311
328
  )
312
-
313
- # 3. ##Input
314
- llm_prompt_parts.append("\n##Input")
315
329
  llm_prompt_parts.append(
316
- 'You will be given a JSON formatted input containing entries with "id" and "input" fields.'
330
+ "3. If the input contains:Proper nouns, code, or non-translatable technical terms, retain them in the original form."
317
331
  )
318
332
 
319
- # 4. ##Output
320
- llm_prompt_parts.append("\n##Output")
333
+ # 4. ## Input/Output Format:
334
+ llm_prompt_parts.append("\n## Input/Output Format:")
321
335
  llm_prompt_parts.append(
322
- f'For each entry in the JSON, translate the contents of the "input" field into {self.translation_config.lang_out}.'
336
+ '1. You will receive a JSON object with entries containing "id" and "input" fields.'
323
337
  )
324
338
  llm_prompt_parts.append(
325
- 'Write the translation back into the "output" field for that entry.'
339
+ '2. Your task is to translate the value of "input" into zh-CN, while applying the rules above.'
340
+ )
341
+ llm_prompt_parts.append(
342
+ '3. Return a new JSON object with the same "id" and the translated "output" field.'
326
343
  )
327
344
  llm_prompt_parts.append(
328
345
  "Please return the translated json directly without wrapping ```json``` tag or include any additional information."
329
346
  )
330
347
 
331
- # 5. ##example
332
- llm_prompt_parts.append("\n##example")
348
+ # 5. ##example (Renumbered from 5 to 4)
349
+ llm_prompt_parts.append("\n## Example:")
333
350
  llm_prompt_parts.append("Here is an example of the expected format:")
334
351
  llm_prompt_parts.append("") # Blank line
335
352
  llm_prompt_parts.append("<example>")
@@ -355,36 +372,8 @@ class ILTranslatorLLMOnly:
355
372
  llm_prompt_parts.append("```")
356
373
  llm_prompt_parts.append("</example>")
357
374
 
358
- # 6. ##Others (contextual hints)
359
- other_hints = []
360
- hint_idx = 0
361
- if title_paragraph:
362
- other_hints.append(
363
- f"{hint_idx}. The first title in the full text: {title_paragraph.unicode}"
364
- )
365
- hint_idx += 1
366
-
367
- if local_title_paragraph:
368
- # Check if it's different from the global title_paragraph before adding
369
- is_different_from_global = True
370
- if title_paragraph:
371
- if local_title_paragraph.debug_id == title_paragraph.debug_id:
372
- is_different_from_global = False
373
-
374
- if is_different_from_global:
375
- other_hints.append(
376
- f"{hint_idx}. The most similar title in the full text: {local_title_paragraph.unicode}"
377
- )
378
- hint_idx += 1
379
-
380
- if other_hints:
381
- llm_prompt_parts.append("\n##Others")
382
- llm_prompt_parts.append(
383
- "When translating, please refer to the following information to improve translation quality:"
384
- )
385
- llm_prompt_parts.extend(other_hints)
386
-
387
- llm_prompt_parts.append("\n## Actual Input")
375
+ # 6. ## Here is the input:
376
+ llm_prompt_parts.append("\n## Here is the input:")
388
377
 
389
378
  # Combine all parts for the main prompt
390
379
  main_prompt_content = "\n".join(llm_prompt_parts)
@@ -405,6 +405,9 @@ def fix_null_xref(doc: Document) -> None:
405
405
  elif obj and "/ASCII85Decode" in obj: # make pdfminer happy
406
406
  data = doc.xref_stream(i)
407
407
  doc.update_stream(i, data)
408
+ elif obj and "/LZWDecode" in obj:
409
+ data = doc.xref_stream(i)
410
+ doc.update_stream(i, data)
408
411
  except Exception:
409
412
  doc.update_object(i, "[]")
410
413
 
@@ -23,7 +23,7 @@ from babeldoc.translation_config import TranslationConfig
23
23
  from babeldoc.translation_config import WatermarkOutputMode
24
24
 
25
25
  logger = logging.getLogger(__name__)
26
- __version__ = "0.3.51"
26
+ __version__ = "0.3.53"
27
27
 
28
28
 
29
29
  def create_parser():
@@ -167,9 +167,20 @@ def main():
167
167
  "--json-path",
168
168
  help="Path to il_translated.json (if not provided, will use the latest file)",
169
169
  )
170
+ parser.add_argument(
171
+ "--working-folder",
172
+ help="Path to the working folder containing il_translated.json files",
173
+ )
170
174
 
171
175
  args = parser.parse_args()
172
176
 
177
+ if args.working_folder:
178
+ global WORKING_FOLDER
179
+ WORKING_FOLDER = Path(args.working_folder)
180
+ if not WORKING_FOLDER.exists():
181
+ print(f"Error: Working folder does not exist: {WORKING_FOLDER}")
182
+ return 1
183
+
173
184
  # Determine JSON file path
174
185
  json_path = None
175
186
  if args.json_path:
@@ -0,0 +1,171 @@
1
+ # Supported Languages
2
+
3
+ For languages in the table below that do not rely on ligature support, BabelDOC provides good support. For languages
4
+ that partially rely on ligatures, BabelDOC's translation results can generally meet self-reading needs. For languages
5
+ that completely rely on ligatures (such as some Indian languages), BabelDOC does not currently support them.
6
+
7
+ We are working hard to develop support for ligatures as soon as possible.
8
+ <!-- | Kazakh (Cyrillic) | kk | None | -->
9
+
10
+ | Language | Language Code | Ligature Dependency |
11
+ |:--------------------------------|:--------------|:--------------------|
12
+ | English | EN | None |
13
+ | Simplified Chinese | zh-CN | None |
14
+ | Traditional Chinese - Hong Kong | zh-HK | None |
15
+ | Traditional Chinese - Taiwan | zh-TW | None |
16
+ | Japanese | JA | None |
17
+ | Korean | KO | None |
18
+ | Polish | PL | Partial |
19
+ | Russian | RU | None |
20
+ | Spanish | es | None |
21
+ | Portuguese | pt | None |
22
+ | French | fr | Partial |
23
+ | Malay | ms | None |
24
+ | Indonesian | id | None |
25
+ | Turkmen | tk | None |
26
+ | Filipino (Tagalog) | tl | None |
27
+ | Vietnamese | vi | None |
28
+ | Kazakh (Latin) | kk | None |
29
+ | German | de | None |
30
+ | Dutch | nl | None |
31
+ | Irish | ga | None |
32
+ | Italian | it | None |
33
+ | Greek | el | None |
34
+ | Swedish | sv | None |
35
+ | Danish | da | None |
36
+ | Norwegian | no | None |
37
+ | Icelandic | is | None |
38
+ | Finnish | fi | None |
39
+ | Ukrainian | uk | None |
40
+ | Czech | cs | None |
41
+ | Romanian | ro | None |
42
+ | Hungarian | hu | None |
43
+ | Slovak | sk | None |
44
+ | Croatian | hr | None |
45
+ | Estonian | et | None |
46
+ | Latvian | lv | None |
47
+ | Lithuanian | lt | None |
48
+ | Belarusian | be | None |
49
+ | Macedonian | mk | None |
50
+ | Albanian | sq | None |
51
+ | Serbian (Cyrillic) | sr | Partial |
52
+ | Serbian (Latin) | sr | Partial |
53
+ | Slovenian | sl | None |
54
+ | Catalan | ca | None |
55
+ | Bulgarian | bg | None |
56
+ | Maltese | mt | None |
57
+ | Swahili | sw | None |
58
+ | Amharic | am | None |
59
+ | Oromo | om | None |
60
+ | Tigrinya | ti | None |
61
+ | Haitian Creole | ht | None |
62
+ | Latin | la | None |
63
+ | Lao | lo | None |
64
+ | Malayalam | ml | None |
65
+ | Gujarati | gu | None |
66
+ | Thai | th | None |
67
+ | Burmese | my | Partial |
68
+ | Tamil | ta | None |
69
+ | Telugu | te | None |
70
+ | Oriya | or | Partial |
71
+ | Armenian | hy | None |
72
+ | Mongolian (Cyrillic) | mn | None |
73
+ | Georgian | ka | None |
74
+ | Khmer | km | None |
75
+ | Bosnian | bs | None |
76
+ | Luxembourgish | lb | None |
77
+ | Moldovan | ro | None |
78
+ | Moldovan (Cyrillic) | ro | None |
79
+ | Romansh | rm | None |
80
+ | Turkish | tr | None |
81
+ | Sinhala | si | None |
82
+ | Uzbek | uz | None |
83
+ | Kyrgyz | ky | None |
84
+ | Tajik | tg | None |
85
+ | Abkhazian | ab | None |
86
+ | Afar | aa | None |
87
+ | Afrikaans | af | None |
88
+ | Akan | ak | None |
89
+ | Aragonese | an | None |
90
+ | Avaric | av | None |
91
+ | Ewe | ee | None |
92
+ | Aymara | ay | None |
93
+ | Ojibwa | oj | None |
94
+ | Occitan | oc | None |
95
+ | Oriya | or | None |
96
+ | Ossetian | os | None |
97
+ | Pali | pi | None |
98
+ | Bashkir | ba | None |
99
+ | Basque | eu | None |
100
+ | Breton | br | None |
101
+ | Chamorro | ch | None |
102
+ | Chechen | ce | None |
103
+ | Chuvash | cv | None |
104
+ | Tswana | tn | None |
105
+ | Ndebele, South | nr | None |
106
+ | Ndonga | ng | None |
107
+ | Faroese | fo | None |
108
+ | Fijian | fj | None |
109
+ | Frisian, Western | fy | None |
110
+ | Ganda | lg | None |
111
+ | Kongo | kg | None |
112
+ | Kalaallisut | kl | None |
113
+ | Church Slavic | cu | None |
114
+ | Guarani | gn | None |
115
+ | Interlingua | ia | None |
116
+ | Herero | hz | None |
117
+ | Kikuyu | ki | None |
118
+ | Rundi | rn | None |
119
+ | Kinyarwanda | rw | None |
120
+ | Kirghiz | ky | None |
121
+ | Galician | gl | None |
122
+ | Kanuri | kr | None |
123
+ | Cornish | kw | None |
124
+ | Komi | kv | None |
125
+ | Xhosa | xh | None |
126
+ | Corsican | co | None |
127
+ | Cree | cr | None |
128
+ | Croatian | hr | None |
129
+ | Quechua | qu | None |
130
+ | Kurdish (Latin) | ku | None |
131
+ | Kuanyama | kj | None |
132
+ | Limburgan | li | None |
133
+ | Lingala | ln | None |
134
+ | Manx | gv | None |
135
+ | Malagasy | mg | None |
136
+ | Marshallese | mh | None |
137
+ | Maori | mi | None |
138
+ | Navajo | nv | None |
139
+ | Nauru | na | None |
140
+ | Nyanja | ny | None |
141
+ | Norwegian Nynorsk | nn | None |
142
+ | Sardinian | sc | None |
143
+ | Northern Sami | se | None |
144
+ | Samoan | sm | None |
145
+ | Sango | sg | None |
146
+ | Shona | sn | None |
147
+ | Esperanto | eo | None |
148
+ | Scottish Gaelic | gd | None |
149
+ | Somali | so | None |
150
+ | Southern Sotho | st | None |
151
+ | Tagalog | tl | None |
152
+ | Tatar | tt | None |
153
+ | Tahitian | ty | None |
154
+ | Tongan | to | None |
155
+ | Twi | tw | None |
156
+ | Walloon | wa | None |
157
+ | Welsh | cy | None |
158
+ | Venda | ve | None |
159
+ | Volapük | vo | None |
160
+ | Interlingue | ie | None |
161
+ | Hiri Motu | ho | None |
162
+ | Igbo | ig | None |
163
+ | Ido | io | None |
164
+ | Inuktitut | iu | None |
165
+ | Inupiaq | ik | None |
166
+ | Sichuan Yi | ii | None |
167
+ | Yoruba | yo | None |
168
+ | Zhuang | za | None |
169
+ | Tsonga | ts | None |
170
+ | Zulu | zu | None |
171
+ | Brazilian Portuguese | pt-BR | None |
@@ -132,7 +132,7 @@ not_in_nav: |
132
132
  # Page tree
133
133
  nav:
134
134
  - Home: index.md
135
- - Supported languages: supported_languages.md
135
+ - Supported Languages: supported_languages.md
136
136
  - API:
137
137
  - Async Translation API: ImplementationDetails/AsyncTranslate/AsyncTranslate.md
138
138
  - Implementation Details:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "BabelDOC"
3
- version = "0.3.51"
3
+ version = "0.3.53"
4
4
  description = "Yet Another Document Translator"
5
5
  license = "AGPL-3.0"
6
6
  readme = "README.md"
@@ -150,7 +150,7 @@ pythonpath = [".", "src"]
150
150
  testpaths = ["tests"]
151
151
 
152
152
  [bumpver]
153
- current_version = "0.3.51"
153
+ current_version = "0.3.53"
154
154
  version_pattern = "MAJOR.MINOR.PATCH[.PYTAGNUM]"
155
155
 
156
156
  [bumpver.file_patterns]
@@ -48,7 +48,7 @@ wheels = [
48
48
 
49
49
  [[package]]
50
50
  name = "babeldoc"
51
- version = "0.3.51"
51
+ version = "0.3.53"
52
52
  source = { editable = "." }
53
53
  dependencies = [
54
54
  { name = "bitstring" },
@@ -1 +0,0 @@
1
- __version__ = "0.3.51"
@@ -1,168 +0,0 @@
1
- # Supported Languages
2
-
3
- For languages in the table below that do not rely on ligature support, BabelDOC provides good support. For languages that partially rely on ligatures, BabelDOC's translation results can generally meet self-reading needs. For languages that completely rely on ligatures (such as some Indian languages), BabelDOC does not currently support them.
4
-
5
- We are working hard to develop support for ligatures as soon as possible.
6
- <!-- | Kazakh (Cyrillic) | kk | None | -->
7
-
8
- | Language | Language Code | Ligature Dependency |
9
- | :------------------- | :------------ | :------------------ |
10
- | English | EN | None |
11
- | Simplified Chinese | zh-CN | None |
12
- | Traditional Chinese - Hong Kong| zh-HK | None |
13
- | Traditional Chinese - Taiwan | zh-TW | None |
14
- | Japanese | JA | None |
15
- | Korean | KO | None |
16
- | Polish | PL | Partial |
17
- | Russian | RU | None |
18
- | Spanish | es | None |
19
- | Portuguese | pt | None |
20
- | French | fr | Partial |
21
- | Malay | ms | None |
22
- | Indonesian | id | None |
23
- | Turkmen | tk | None |
24
- | Filipino (Tagalog) | tl | None |
25
- | Vietnamese | vi | None |
26
- | Kazakh (Latin) | kk | None |
27
- | German | de | None |
28
- | Dutch | nl | None |
29
- | Irish | ga | None |
30
- | Italian | it | None |
31
- | Greek | el | None |
32
- | Swedish | sv | None |
33
- | Danish | da | None |
34
- | Norwegian | no | None |
35
- | Icelandic | is | None |
36
- | Finnish | fi | None |
37
- | Ukrainian | uk | None |
38
- | Czech | cs | None |
39
- | Romanian | ro | None |
40
- | Hungarian | hu | None |
41
- | Slovak | sk | None |
42
- | Croatian | hr | None |
43
- | Estonian | et | None |
44
- | Latvian | lv | None |
45
- | Lithuanian | lt | None |
46
- | Belarusian | be | None |
47
- | Macedonian | mk | None |
48
- | Albanian | sq | None |
49
- | Serbian (Cyrillic) | sr | Partial |
50
- | Serbian (Latin) | sr | Partial |
51
- | Slovenian | sl | None |
52
- | Catalan | ca | None |
53
- | Bulgarian | bg | None |
54
- | Maltese | mt | None |
55
- | Swahili | sw | None |
56
- | Amharic | am | None |
57
- | Oromo | om | None |
58
- | Tigrinya | ti | None |
59
- | Haitian Creole | ht | None |
60
- | Latin | la | None |
61
- | Lao | lo | None |
62
- | Malayalam | ml | None |
63
- | Gujarati | gu | None |
64
- | Thai | th | None |
65
- | Burmese | my | Partial |
66
- | Tamil | ta | None |
67
- | Telugu | te | None |
68
- | Oriya | or | Partial |
69
- | Armenian | hy | None |
70
- | Mongolian (Cyrillic) | mn | None |
71
- | Georgian | ka | None |
72
- | Khmer | km | None |
73
- | Bosnian | bs | None |
74
- | Luxembourgish | lb | None |
75
- | Moldovan | ro | None |
76
- | Moldovan (Cyrillic) | ro | None |
77
- | Romansh | rm | None |
78
- | Turkish | tr | None |
79
- | Sinhala | si | None |
80
- | Uzbek | uz | None |
81
- | Kyrgyz | ky | None |
82
- | Tajik | tg | None |
83
- | Abkhazian | ab | None |
84
- | Afar | aa | None |
85
- | Afrikaans | af | None |
86
- | Akan | ak | None |
87
- | Aragonese | an | None |
88
- | Avaric | av | None |
89
- | Ewe | ee | None |
90
- | Aymara | ay | None |
91
- | Ojibwa | oj | None |
92
- | Occitan | oc | None |
93
- | Oriya | or | None |
94
- | Ossetian | os | None |
95
- | Pali | pi | None |
96
- | Bashkir | ba | None |
97
- | Basque | eu | None |
98
- | Breton | br | None |
99
- | Chamorro | ch | None |
100
- | Chechen | ce | None |
101
- | Chuvash | cv | None |
102
- | Tswana | tn | None |
103
- | Ndebele, South | nr | None |
104
- | Ndonga | ng | None |
105
- | Faroese | fo | None |
106
- | Fijian | fj | None |
107
- | Frisian, Western | fy | None |
108
- | Ganda | lg | None |
109
- | Kongo | kg | None |
110
- | Kalaallisut | kl | None |
111
- | Church Slavic | cu | None |
112
- | Guarani | gn | None |
113
- | Interlingua | ia | None |
114
- | Herero | hz | None |
115
- | Kikuyu | ki | None |
116
- | Rundi | rn | None |
117
- | Kinyarwanda | rw | None |
118
- | Kirghiz | ky | None |
119
- | Galician | gl | None |
120
- | Kanuri | kr | None |
121
- | Cornish | kw | None |
122
- | Komi | kv | None |
123
- | Xhosa | xh | None |
124
- | Corsican | co | None |
125
- | Cree | cr | None |
126
- | Croatian | hr | None |
127
- | Quechua | qu | None |
128
- | Kurdish (Latin) | ku | None |
129
- | Kuanyama | kj | None |
130
- | Limburgan | li | None |
131
- | Lingala | ln | None |
132
- | Manx | gv | None |
133
- | Malagasy | mg | None |
134
- | Marshallese | mh | None |
135
- | Maori | mi | None |
136
- | Navajo | nv | None |
137
- | Nauru | na | None |
138
- | Nyanja | ny | None |
139
- | Norwegian Nynorsk | nn | None |
140
- | Sardinian | sc | None |
141
- | Northern Sami | se | None |
142
- | Samoan | sm | None |
143
- | Sango | sg | None |
144
- | Shona | sn | None |
145
- | Esperanto | eo | None |
146
- | Scottish Gaelic | gd | None |
147
- | Somali | so | None |
148
- | Southern Sotho | st | None |
149
- | Tagalog | tl | None |
150
- | Tatar | tt | None |
151
- | Tahitian | ty | None |
152
- | Tongan | to | None |
153
- | Twi | tw | None |
154
- | Walloon | wa | None |
155
- | Welsh | cy | None |
156
- | Venda | ve | None |
157
- | Volapük | vo | None |
158
- | Interlingue | ie | None |
159
- | Hiri Motu | ho | None |
160
- | Igbo | ig | None |
161
- | Ido | io | None |
162
- | Inuktitut | iu | None |
163
- | Inupiaq | ik | None |
164
- | Sichuan Yi | ii | None |
165
- | Yoruba | yo | None |
166
- | Zhuang | za | None |
167
- | Tsonga | ts | None |
168
- | Zulu | zu | None |
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes