subtranslate-ai 0.9.0__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 (62) hide show
  1. subtranslate_ai-0.9.0/CHANGELOG.md +79 -0
  2. subtranslate_ai-0.9.0/CONTRIBUTING.md +169 -0
  3. subtranslate_ai-0.9.0/LICENSE +21 -0
  4. subtranslate_ai-0.9.0/MANIFEST.in +7 -0
  5. subtranslate_ai-0.9.0/PKG-INFO +670 -0
  6. subtranslate_ai-0.9.0/README.md +628 -0
  7. subtranslate_ai-0.9.0/SECURITY.md +64 -0
  8. subtranslate_ai-0.9.0/pyproject.toml +90 -0
  9. subtranslate_ai-0.9.0/setup.cfg +4 -0
  10. subtranslate_ai-0.9.0/src/subtitle_translator/__init__.py +5 -0
  11. subtranslate_ai-0.9.0/src/subtitle_translator/app.py +265 -0
  12. subtranslate_ai-0.9.0/src/subtitle_translator/batch.py +109 -0
  13. subtranslate_ai-0.9.0/src/subtitle_translator/cli.py +570 -0
  14. subtranslate_ai-0.9.0/src/subtitle_translator/config.py +34 -0
  15. subtranslate_ai-0.9.0/src/subtitle_translator/consistency.py +307 -0
  16. subtranslate_ai-0.9.0/src/subtitle_translator/consistency_report.py +114 -0
  17. subtranslate_ai-0.9.0/src/subtitle_translator/consistency_review.py +111 -0
  18. subtranslate_ai-0.9.0/src/subtitle_translator/glossary.py +177 -0
  19. subtranslate_ai-0.9.0/src/subtitle_translator/models.py +72 -0
  20. subtranslate_ai-0.9.0/src/subtitle_translator/persistence.py +39 -0
  21. subtranslate_ai-0.9.0/src/subtitle_translator/prompts.py +58 -0
  22. subtranslate_ai-0.9.0/src/subtitle_translator/providers/__init__.py +61 -0
  23. subtranslate_ai-0.9.0/src/subtitle_translator/providers/base.py +97 -0
  24. subtranslate_ai-0.9.0/src/subtitle_translator/providers/factory.py +192 -0
  25. subtranslate_ai-0.9.0/src/subtitle_translator/providers/gemini_consistency_reviewer.py +189 -0
  26. subtranslate_ai-0.9.0/src/subtitle_translator/providers/gemini_provider.py +155 -0
  27. subtranslate_ai-0.9.0/src/subtitle_translator/providers/openai_consistency_reviewer.py +74 -0
  28. subtranslate_ai-0.9.0/src/subtitle_translator/providers/openai_provider.py +96 -0
  29. subtranslate_ai-0.9.0/src/subtitle_translator/resources/batch_prompt.txt +43 -0
  30. subtranslate_ai-0.9.0/src/subtitle_translator/resources/consistency_prompt.txt +50 -0
  31. subtranslate_ai-0.9.0/src/subtitle_translator/resources/prompt.txt +11 -0
  32. subtranslate_ai-0.9.0/src/subtitle_translator/srt.py +58 -0
  33. subtranslate_ai-0.9.0/src/subtitle_translator/subtitle_translation.py +138 -0
  34. subtranslate_ai-0.9.0/src/subtitle_translator/translator.py +32 -0
  35. subtranslate_ai-0.9.0/src/subtitle_translator/version.py +3 -0
  36. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/PKG-INFO +670 -0
  37. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/SOURCES.txt +60 -0
  38. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/dependency_links.txt +1 -0
  39. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/entry_points.txt +2 -0
  40. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/requires.txt +19 -0
  41. subtranslate_ai-0.9.0/src/subtranslate_ai.egg-info/top_level.txt +1 -0
  42. subtranslate_ai-0.9.0/tests/test_app.py +841 -0
  43. subtranslate_ai-0.9.0/tests/test_batch.py +145 -0
  44. subtranslate_ai-0.9.0/tests/test_cli.py +1207 -0
  45. subtranslate_ai-0.9.0/tests/test_cli_integration.py +506 -0
  46. subtranslate_ai-0.9.0/tests/test_consistency.py +138 -0
  47. subtranslate_ai-0.9.0/tests/test_consistency_report.py +91 -0
  48. subtranslate_ai-0.9.0/tests/test_consistency_review.py +237 -0
  49. subtranslate_ai-0.9.0/tests/test_gemini_cli_integration.py +157 -0
  50. subtranslate_ai-0.9.0/tests/test_gemini_consistency_reviewer.py +275 -0
  51. subtranslate_ai-0.9.0/tests/test_gemini_provider.py +150 -0
  52. subtranslate_ai-0.9.0/tests/test_glossary.py +245 -0
  53. subtranslate_ai-0.9.0/tests/test_models.py +60 -0
  54. subtranslate_ai-0.9.0/tests/test_openai_consistency_reviewer.py +150 -0
  55. subtranslate_ai-0.9.0/tests/test_openai_provider.py +357 -0
  56. subtranslate_ai-0.9.0/tests/test_package.py +355 -0
  57. subtranslate_ai-0.9.0/tests/test_prompts.py +75 -0
  58. subtranslate_ai-0.9.0/tests/test_provider_base.py +113 -0
  59. subtranslate_ai-0.9.0/tests/test_provider_factory.py +160 -0
  60. subtranslate_ai-0.9.0/tests/test_srt.py +81 -0
  61. subtranslate_ai-0.9.0/tests/test_subtitle_translation.py +371 -0
  62. subtranslate_ai-0.9.0/tests/test_translator.py +81 -0
@@ -0,0 +1,79 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ > **Maintainer note:** When releasing a new version, move the entries below from
11
+ > `[Unreleased]` into a new `## [x.y.z] – YYYY-MM-DD` section. Add a link at the
12
+ > bottom of the file comparing the new tag with the previous one.
13
+
14
+ ---
15
+
16
+ ## [Unreleased]
17
+
18
+ ## [0.9.0] - 2026-09-05
19
+
20
+ ### Added
21
+
22
+ - **Core translation engine** – SRT subtitle translation using LLM providers.
23
+ Batch translation preserves subtitle indices, timestamps, formatting, and
24
+ line breaks.
25
+ - **OpenAI provider** – Translation and consistency review via the OpenAI API.
26
+ Configured with `OPENAI_API_KEY` and optional `OPENAI_MODEL`.
27
+ - **Gemini provider** – Translation and consistency review via the Google Gemini
28
+ API. Configured with `GEMINI_API_KEY` and optional `GEMINI_MODEL`.
29
+ - **Provider selection** – `--provider openai|gemini` (default: `openai`).
30
+ Provider names are case-insensitive.
31
+ - **Rolling context** – Each translation batch optionally receives recently
32
+ accepted translations as read-only guidance, configurable with
33
+ `--context-size` (default: 10, disable with 0).
34
+ - **Glossary support** – `--glossary PATH` accepts a UTF-8 JSON file of
35
+ approved source-to-target terminology. Glossary languages must match the CLI
36
+ source and target languages.
37
+ - **Optional consistency report** – `--consistency-report PATH` triggers a
38
+ separate advisory review after translation, writing a Markdown findings
39
+ report. The review never modifies the translated SRT.
40
+ - **Cross-provider review** – `--review-provider` selects an independent
41
+ provider for consistency review. `--review-model` overrides the review model
42
+ independently of `--model`.
43
+ - **Standalone review command** – `subtitle-translator review SOURCE TRANSLATED`
44
+ generates a consistency report from existing SRT files without re-translating.
45
+ Both files must have matching subtitle indices and timestamps.
46
+ - **Legacy CLI compatibility** – Existing commands using positional SRT path
47
+ arguments continue to work without a `translate` subcommand.
48
+ - **Automatic retry and resume** – Failed or interrupted translations can be
49
+ retried; batch progress is preserved across runs.
50
+ - **Output-file safety** – Existing output files and report files are never
51
+ overwritten by default. Writes use atomic replacement where supported.
52
+ - **`--version` flag** – Reports the installed package version without requiring
53
+ provider SDKs.
54
+ - **Optional dependency extras** – `openai`, `gemini`, `all`, and `dev` extras
55
+ allow selective installation of provider SDKs.
56
+ - **Packaging and distribution** – Wheel and source distribution build correctly
57
+ with all prompt resources and the LICENSE file included.
58
+ - **CI** – GitHub Actions workflow running tests, Ruff, build, distribution
59
+ verification, and installed-wheel verification across Python 3.11–3.13.
60
+ - **Release automation** – GitHub Actions release workflow using PyPI Trusted
61
+ Publishing (OIDC); no stored API token required.
62
+ - **Documentation** – README, CONTRIBUTING, SECURITY, CHANGELOG, architecture
63
+ overview, usage guide, release checklist, and sample files.
64
+
65
+ ### Changed
66
+
67
+ - Improved help text and error messages to align with user-visible CLI behavior.
68
+ - Tightened provider-neutral import isolation: provider SDKs are not imported
69
+ unless the relevant extra is installed and the provider is selected.
70
+
71
+ ### Security
72
+
73
+ - Provider SDKs are optional extras; a user selecting a provider without its
74
+ SDK receives a clear error rather than an import-time failure at startup.
75
+ - Subtitle source files are never modified by translation or review operations.
76
+ - Consistency reports do not overwrite existing files.
77
+
78
+ [Unreleased]: https://github.com/dhofverberg/subtitle-translator/compare/v0.9.0...HEAD
79
+ [0.9.0]: https://github.com/dhofverberg/subtitle-translator/releases/tag/v0.9.0
@@ -0,0 +1,169 @@
1
+ # Contributing to Subtitle Translator
2
+
3
+ Thank you for your interest in contributing! This document covers development
4
+ setup, conventions, and the process for reporting bugs and proposing changes.
5
+
6
+ ## Supported Python versions
7
+
8
+ Python **3.11, 3.12, and 3.13** are supported and tested in CI.
9
+
10
+ ## Setting up the development environment
11
+
12
+ 1. Clone the repository:
13
+
14
+ ```bash
15
+ git clone https://github.com/dhofverberg/subtitle-translator.git
16
+ cd subtitle-translator
17
+ ```
18
+
19
+ 2. Create and activate a virtual environment:
20
+
21
+ ```bash
22
+ python -m venv .venv
23
+ # macOS / Linux
24
+ source .venv/bin/activate
25
+ # Windows PowerShell
26
+ .venv\Scripts\Activate.ps1
27
+ ```
28
+
29
+ 3. Install all provider extras and development tools:
30
+
31
+ ```bash
32
+ python -m pip install -e ".[all,dev]"
33
+ ```
34
+
35
+ If you only need one provider:
36
+
37
+ ```bash
38
+ python -m pip install -e ".[openai,dev]"
39
+ python -m pip install -e ".[gemini,dev]"
40
+ ```
41
+
42
+ ## Running the tests
43
+
44
+ ```bash
45
+ pytest
46
+ ```
47
+
48
+ Run a specific file:
49
+
50
+ ```bash
51
+ pytest tests/test_cli.py
52
+ ```
53
+
54
+ All automated tests must pass without making real API calls. Use fake/stub
55
+ clients (see `tests/` for examples) whenever provider interactions are tested.
56
+
57
+ ## Running the linter
58
+
59
+ ```bash
60
+ ruff check .
61
+ ```
62
+
63
+ Ruff is configured in `pyproject.toml`. Fix reported issues before opening a
64
+ pull request.
65
+
66
+ ## Building the wheel and source distribution
67
+
68
+ ```bash
69
+ python -m build
70
+ ```
71
+
72
+ Inspect the distribution contents:
73
+
74
+ ```bash
75
+ python -m twine check dist/*
76
+ ```
77
+
78
+ ## Verifying the installed wheel
79
+
80
+ Build the wheel, then install it into a clean environment outside the source
81
+ tree and run the CLI:
82
+
83
+ ```bash
84
+ # macOS / Linux
85
+ python -m venv /tmp/st-verify
86
+ wheel_path="$(python -c 'from pathlib import Path; print(next(Path(\"dist\").glob(\"subtranslate_ai-*.whl\")).resolve())')"
87
+ wheel_uri="$(python -c 'from pathlib import Path; import sys; print(Path(sys.argv[1]).as_uri())' "$wheel_path")"
88
+ /tmp/st-verify/bin/pip install "subtranslate-ai[all] @ $wheel_uri"
89
+ /tmp/st-verify/bin/subtitle-translator --version
90
+ /tmp/st-verify/bin/subtitle-translator --help
91
+ /tmp/st-verify/bin/subtitle-translator translate --help
92
+ /tmp/st-verify/bin/subtitle-translator review --help
93
+ ```
94
+
95
+ ```powershell
96
+ # Windows PowerShell
97
+ python -m venv "$env:TEMP\st-verify"
98
+ $wheelPath = (Get-ChildItem dist\subtranslate_ai-*.whl | Select-Object -First 1).FullName
99
+ $wheelUri = python -c "from pathlib import Path; import sys; print(Path(sys.argv[1]).resolve().as_uri())" "$wheelPath"
100
+ & "$env:TEMP\st-verify\Scripts\pip.exe" install "subtranslate-ai[all] @ $wheelUri"
101
+ & "$env:TEMP\st-verify\Scripts\subtitle-translator.exe" --version
102
+ & "$env:TEMP\st-verify\Scripts\subtitle-translator.exe" --help
103
+ & "$env:TEMP\st-verify\Scripts\subtitle-translator.exe" translate --help
104
+ & "$env:TEMP\st-verify\Scripts\subtitle-translator.exe" review --help
105
+ ```
106
+ ## Architecture overview
107
+
108
+ See [`docs/architecture.md`](docs/architecture.md) for a concise description of
109
+ the provider-neutral core, translation and review adapters, file boundaries, and
110
+ safety invariants.
111
+
112
+ ## Adding a provider integration
113
+
114
+ 1. Create a new module under `src/subtitle_translator/providers/`.
115
+ 2. Implement the `TranslationProvider` interface from `providers/base.py` for
116
+ translation, or `ConsistencyReviewer` from `consistency.py` for review.
117
+ 3. Register the provider in `providers/factory.py`.
118
+ 4. Add the provider SDK as an optional extra in `pyproject.toml`.
119
+ 5. Write tests using a fake/stub client — do not make real API calls in
120
+ automated tests.
121
+ 6. Do not import the provider SDK at module load time; gate imports behind the
122
+ point where the provider is first used.
123
+
124
+ ## Keeping the core provider-neutral
125
+
126
+ The `models.py`, `batch.py`, `srt.py`, `glossary.py`, `consistency.py`, and
127
+ `prompts.py` modules must not import any provider SDK. Verify this with the
128
+ existing provider-neutral import tests.
129
+
130
+ ## Writing tests with fake clients
131
+
132
+ Provider tests use fake/stub implementations of `TranslationProvider` and
133
+ `ConsistencyReviewer`. See `tests/test_cli_integration.py` for examples. Never
134
+ use `monkeypatch` to replace transport-level calls when a higher-level interface
135
+ can be faked instead.
136
+
137
+ ## Adding changelog entries
138
+
139
+ Add a one-line summary under the appropriate heading in the `[Unreleased]`
140
+ section of `CHANGELOG.md` for every user-visible change. See the format in that
141
+ file. Do not edit released sections.
142
+
143
+ ## Writing pull requests
144
+
145
+ - Keep the scope focused: one logical change per PR.
146
+ - Include or update tests for every behavioral change.
147
+ - Ensure `ruff check .` passes.
148
+ - Ensure `pytest` passes.
149
+ - Ensure `python -m build` and `python -m twine check dist/*` pass.
150
+ - Do not commit API keys, provider credentials, or personal environment details.
151
+ - Do not commit copyrighted subtitle files. Use original synthetic content in
152
+ samples and test fixtures.
153
+ - Update documentation when behavior visible to users changes.
154
+ - Add a changelog entry for every user-visible change.
155
+
156
+ ## Documentation-only changes
157
+
158
+ Documentation-only changes (README, docs/, CHANGELOG, etc.) do not require
159
+ new tests, but must not break existing ones. Ruff should still pass.
160
+
161
+ ## Reporting bugs and proposing features
162
+
163
+ Use the GitHub issue tracker:
164
+ <https://github.com/dhofverberg/subtitle-translator/issues>
165
+
166
+ See the issue templates for the information to include. Never include real API
167
+ keys or private subtitle content in issues.
168
+
169
+ For security vulnerabilities, see [SECURITY.md](SECURITY.md).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Hofverberg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ include README.md
2
+ include CHANGELOG.md
3
+ include CONTRIBUTING.md
4
+ include SECURITY.md
5
+ include LICENSE
6
+
7
+ recursive-include src/subtitle_translator/resources *.txt