translate-dir-lib 0.1.2__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 (74) hide show
  1. translate_dir_lib-0.1.2/.github/workflows/release.yml +42 -0
  2. translate_dir_lib-0.1.2/.github/workflows/tests.yml +28 -0
  3. translate_dir_lib-0.1.2/.gitignore +7 -0
  4. translate_dir_lib-0.1.2/.python-version +1 -0
  5. translate_dir_lib-0.1.2/CITATION.cff +12 -0
  6. translate_dir_lib-0.1.2/CONTRIBUTING.md +25 -0
  7. translate_dir_lib-0.1.2/LICENSE +201 -0
  8. translate_dir_lib-0.1.2/PKG-INFO +108 -0
  9. translate_dir_lib-0.1.2/README.md +86 -0
  10. translate_dir_lib-0.1.2/cache.md +81 -0
  11. translate_dir_lib-0.1.2/docs/cli.md +646 -0
  12. translate_dir_lib-0.1.2/docs/main.md +533 -0
  13. translate_dir_lib-0.1.2/docs/tool-profound-explanation.md +311 -0
  14. translate_dir_lib-0.1.2/docs/typst_parsing_analysis.md +283 -0
  15. translate_dir_lib-0.1.2/main.py +6 -0
  16. translate_dir_lib-0.1.2/pyproject.toml +44 -0
  17. translate_dir_lib-0.1.2/reinstall.sh +2 -0
  18. translate_dir_lib-0.1.2/scripts/myst_roundtrip.py +111 -0
  19. translate_dir_lib-0.1.2/setup.cfg +4 -0
  20. translate_dir_lib-0.1.2/src/cli.py +526 -0
  21. translate_dir_lib-0.1.2/src/trans_lib/__init__.py +0 -0
  22. translate_dir_lib-0.1.2/src/trans_lib/constants.py +12 -0
  23. translate_dir_lib-0.1.2/src/trans_lib/diff.py +41 -0
  24. translate_dir_lib-0.1.2/src/trans_lib/doc_corrector.py +89 -0
  25. translate_dir_lib-0.1.2/src/trans_lib/doc_translator.py +76 -0
  26. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/__init__.py +0 -0
  27. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/latex_chunker.py +276 -0
  28. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/latex_file_translator.py +120 -0
  29. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/myst_chunker.py +98 -0
  30. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/myst_file_translator.py +192 -0
  31. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/notebook_file_translator.py +102 -0
  32. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/typst_chunker.py +434 -0
  33. translate_dir_lib-0.1.2/src/trans_lib/doc_translator_mod/typst_file_translator.py +132 -0
  34. translate_dir_lib-0.1.2/src/trans_lib/enums.py +61 -0
  35. translate_dir_lib-0.1.2/src/trans_lib/errors.py +187 -0
  36. translate_dir_lib-0.1.2/src/trans_lib/helpers.py +350 -0
  37. translate_dir_lib-0.1.2/src/trans_lib/project_config_io.py +133 -0
  38. translate_dir_lib-0.1.2/src/trans_lib/project_config_models.py +327 -0
  39. translate_dir_lib-0.1.2/src/trans_lib/project_manager.py +482 -0
  40. translate_dir_lib-0.1.2/src/trans_lib/project_runtime.py +418 -0
  41. translate_dir_lib-0.1.2/src/trans_lib/prompts.py +567 -0
  42. translate_dir_lib-0.1.2/src/trans_lib/translation_cache/cache_backend.py +389 -0
  43. translate_dir_lib-0.1.2/src/trans_lib/translation_cache/cache_cleaner.py +299 -0
  44. translate_dir_lib-0.1.2/src/trans_lib/translation_cache/cache_rebuilder.py +232 -0
  45. translate_dir_lib-0.1.2/src/trans_lib/translation_cache/translation_cache.py +144 -0
  46. translate_dir_lib-0.1.2/src/trans_lib/translator.py +183 -0
  47. translate_dir_lib-0.1.2/src/trans_lib/translator_corrector.py +28 -0
  48. translate_dir_lib-0.1.2/src/trans_lib/translator_retrieval.py +518 -0
  49. translate_dir_lib-0.1.2/src/trans_lib/vocab_list.py +48 -0
  50. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/__init__.py +0 -0
  51. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/code.py +119 -0
  52. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/latex.py +405 -0
  53. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/mod.py +66 -0
  54. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/myst.py +612 -0
  55. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/typst.py +351 -0
  56. translate_dir_lib-0.1.2/src/trans_lib/xml_manipulator_mod/xml.py +155 -0
  57. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/PKG-INFO +108 -0
  58. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/SOURCES.txt +72 -0
  59. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/dependency_links.txt +1 -0
  60. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/entry_points.txt +2 -0
  61. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/requires.txt +13 -0
  62. translate_dir_lib-0.1.2/src/translate_dir_lib.egg-info/top_level.txt +2 -0
  63. translate_dir_lib-0.1.2/tests/test_cache_clear.py +535 -0
  64. translate_dir_lib-0.1.2/tests/test_cache_sync.py +110 -0
  65. translate_dir_lib-0.1.2/tests/test_chunk_translator.py +569 -0
  66. translate_dir_lib-0.1.2/tests/test_custom_services.py +85 -0
  67. translate_dir_lib-0.1.2/tests/test_needs_review.py +363 -0
  68. translate_dir_lib-0.1.2/tests/test_needs_review_e2e.py +349 -0
  69. translate_dir_lib-0.1.2/tests/test_project_config_paths.py +162 -0
  70. translate_dir_lib-0.1.2/tests/test_typst_chunker.py +60 -0
  71. translate_dir_lib-0.1.2/tests/test_typst_file_translator.py +26 -0
  72. translate_dir_lib-0.1.2/tests/test_typst_xml_tagging.py +251 -0
  73. translate_dir_lib-0.1.2/tests/test_use_reasoning_model.py +318 -0
  74. translate_dir_lib-0.1.2/tests/test_xml_tagging.py +707 -0
@@ -0,0 +1,42 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build distribution
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ - name: Install build frontend
19
+ run: pip install build
20
+
21
+ - name: Build sdist and wheel
22
+ run: python -m build
23
+
24
+ - uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write # trusted publishing — no API token needed
35
+ steps:
36
+ - uses: actions/download-artifact@v4
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+
41
+ - uses: pypa/gh-action-pypi-publish@release/v1
42
+
@@ -0,0 +1,28 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: ["dev"]
6
+ pull_request:
7
+ branches: ["dev", "master"]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v5
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version-file: "pyproject.toml"
23
+
24
+ - name: Install dependencies
25
+ run: uv sync --dev
26
+
27
+ - name: Run tests
28
+ run: uv run pytest
@@ -0,0 +1,7 @@
1
+ **/__pycache__/
2
+ build/
3
+ *.egg-info/
4
+ dist/
5
+ uv.lock
6
+ test-files/
7
+
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,12 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it using the following metadata."
3
+ title: "sci-trans-git"
4
+ version: "1.0.0"
5
+ date-released: 2025-06-30
6
+ authors:
7
+ - family-names: Korotenko
8
+ given-names: Yehor
9
+ orcid: https://orcid.org/0009-0002-4570-2391
10
+ repository-code: https://github.com/DobbiKov/sci-trans-git
11
+ license: MIT
12
+ doi: 10.5281/zenodo.15775111
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ Before contributing, make sure to read [the profound explanation](./docs/tool-profound-explanation.md) in order to understand how the tool work and its idea.
4
+
5
+ Each pull request must contain the following sections:
6
+
7
+ - **Motivation** - describes why this pull request is created in the first place (can be one sentence short).
8
+ - **Explanation** - explains what does the pull request change in the project's code base or architecture.
9
+
10
+ If you want to contribute but don't know what to start with, read the ToDo section in the [README](README.md).
11
+
12
+ All pull requests, ideas and suggestions are welcome!
13
+
14
+ ## Logging and CLI output
15
+
16
+ This project standardizes diagnostics on Loguru and keeps user-facing CLI output as prints:
17
+
18
+ - **Default CLI behavior**: show user-facing `print` output plus Loguru warnings/errors on stderr.
19
+ - **Verbose mode (`--verbose` / `-v`)**: show both `print` output and all Loguru logs (including debug/trace).
20
+
21
+ Conventions:
22
+
23
+ - Use `print` only for user-facing CLI messages (results, progress, prompts).
24
+ - Use `loguru.logger` for diagnostics (debug/info/warn/error, stack traces, internal state).
25
+ - Library code should not configure Loguru; the CLI entrypoint wires log sinks and verbosity.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: translate-dir-lib
3
+ Version: 0.1.2
4
+ Summary: A library for automated directory translation
5
+ Requires-Python: >=3.12
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: google-genai>=1.16.1
9
+ Requires-Dist: httpx>=0.28.1
10
+ Requires-Dist: jupytext>=1.17.1
11
+ Requires-Dist: linkify-it-py>=2.0.3
12
+ Requires-Dist: loguru>=0.7.3
13
+ Requires-Dist: markdown-it-py>=3.0.0
14
+ Requires-Dist: mdit-py-plugins>=0.4.2
15
+ Requires-Dist: pydantic>=2.11.5
16
+ Requires-Dist: pylatexenc>=2.10
17
+ Requires-Dist: tree-sitter-language-pack>=0.9.0
18
+ Requires-Dist: typer>=0.20.0
19
+ Requires-Dist: typst-syntax>=0.1.6
20
+ Requires-Dist: unified-model-caller==0.2.2
21
+ Dynamic: license-file
22
+
23
+ # Translate directory library
24
+
25
+ A library and a CLI to manage the translation text writing projects (e.g: LaTeX,
26
+ Markdown, Jupyter, MyST, Typst). The library is aimed to simplify and automate
27
+ the translation process and compiling of the translated version of the documents.
28
+
29
+ ## Credits
30
+ - **Nicolas M. Thiéry** - for supervising this project.
31
+ - **LISN (Université Paris-Saclay)** - for financing the internship and
32
+ providing workspace.
33
+ - **CentraleSupélec** - for financing the project.
34
+
35
+ ## **Important**
36
+
37
+ > The library is still in an early phase of development and may have bugs and unimplemented features
38
+
39
+ ## Features
40
+
41
+ - [x] Project creation
42
+ - [x] Source language and the source folder to translate setting
43
+ - [x] Target language addition
44
+ - [x] Project files syncing (between languages)
45
+ - [x] Translation cache
46
+ - [x] File translation
47
+ - [x] Translation correction
48
+
49
+ The profound explanation of the logic and algorithms of the tool can be found [here](./docs/tool-profound-explanation.md)
50
+
51
+ ## Installation
52
+
53
+ ### For CLI usage
54
+ 1. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
55
+ 2. Enter to the directory: `cd translate-dir-lib`
56
+ 3. Install the CLI: `uv tool install -e .`
57
+ 4. Use it: `translate-dir`
58
+ ### For in-project library usage
59
+
60
+ 1. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
61
+ 2. Enter to your project where you want to use this library (`cd <your_project_path>`)
62
+ 3. Install the library as a dependency using `pip`: `pip install <path_to_the_library_directory>`
63
+ 4. Enjoy!
64
+
65
+ ### For the library development and contribution uses
66
+
67
+ 1. Ensure you have [uv](https://docs.astral.sh/uv/#__tabbed_1_1) tool installed
68
+ (visit their site for the installation guide)
69
+ 2. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
70
+ 3. Enter `cd translate-dir-lib`
71
+ 4. Install dependencies `uv sync`
72
+ 5. Enjoy
73
+
74
+ ## Testing
75
+ 1. Install the dependencies using `uv sync`
76
+ 2. Run tests: `uv run pytest`
77
+
78
+ ## Documentation
79
+
80
+ - [Library API reference](./docs/main.md)
81
+ - [CLI documentation](./docs/cli.md)
82
+ - [Architecture and algorithms](./docs/tool-profound-explanation.md)
83
+ - [Typst parsing and implementation](./docs/typst_parsing_analysis.md)
84
+
85
+ ## ToDo
86
+
87
+ ## 📚 Citation
88
+
89
+ If you use this software in your research or writing, please cite it as follows:
90
+
91
+ ```bib
92
+ @software{korotenko-sci-trans-git,
93
+ author = {Yehor Korotenko},
94
+ title = {sci-trans-git},
95
+ year = {2025},
96
+ publisher = {GitHub},
97
+ version = {0.2.0-alpha},
98
+ url = {https://github.com/DobbiKov/sci-trans-git},
99
+ doi = {10.5281/zenodo.15775111}
100
+ }
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ The suggestions and pull requests are welcome. Visit the issues pages as well
106
+ as the project's [main page](https://github.com/DobbiKov/sci-trans-git) and the
107
+ [shared document](https://codimd.math.cnrs.fr/sUW9PQ1tTLWcR98UjLHLpw) in order
108
+ to know the current direction and plans of the project.
@@ -0,0 +1,86 @@
1
+ # Translate directory library
2
+
3
+ A library and a CLI to manage the translation text writing projects (e.g: LaTeX,
4
+ Markdown, Jupyter, MyST, Typst). The library is aimed to simplify and automate
5
+ the translation process and compiling of the translated version of the documents.
6
+
7
+ ## Credits
8
+ - **Nicolas M. Thiéry** - for supervising this project.
9
+ - **LISN (Université Paris-Saclay)** - for financing the internship and
10
+ providing workspace.
11
+ - **CentraleSupélec** - for financing the project.
12
+
13
+ ## **Important**
14
+
15
+ > The library is still in an early phase of development and may have bugs and unimplemented features
16
+
17
+ ## Features
18
+
19
+ - [x] Project creation
20
+ - [x] Source language and the source folder to translate setting
21
+ - [x] Target language addition
22
+ - [x] Project files syncing (between languages)
23
+ - [x] Translation cache
24
+ - [x] File translation
25
+ - [x] Translation correction
26
+
27
+ The profound explanation of the logic and algorithms of the tool can be found [here](./docs/tool-profound-explanation.md)
28
+
29
+ ## Installation
30
+
31
+ ### For CLI usage
32
+ 1. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
33
+ 2. Enter to the directory: `cd translate-dir-lib`
34
+ 3. Install the CLI: `uv tool install -e .`
35
+ 4. Use it: `translate-dir`
36
+ ### For in-project library usage
37
+
38
+ 1. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
39
+ 2. Enter to your project where you want to use this library (`cd <your_project_path>`)
40
+ 3. Install the library as a dependency using `pip`: `pip install <path_to_the_library_directory>`
41
+ 4. Enjoy!
42
+
43
+ ### For the library development and contribution uses
44
+
45
+ 1. Ensure you have [uv](https://docs.astral.sh/uv/#__tabbed_1_1) tool installed
46
+ (visit their site for the installation guide)
47
+ 2. Clone the repo: `git clone https://github.com/DobbiKov/translate-dir-lib`
48
+ 3. Enter `cd translate-dir-lib`
49
+ 4. Install dependencies `uv sync`
50
+ 5. Enjoy
51
+
52
+ ## Testing
53
+ 1. Install the dependencies using `uv sync`
54
+ 2. Run tests: `uv run pytest`
55
+
56
+ ## Documentation
57
+
58
+ - [Library API reference](./docs/main.md)
59
+ - [CLI documentation](./docs/cli.md)
60
+ - [Architecture and algorithms](./docs/tool-profound-explanation.md)
61
+ - [Typst parsing and implementation](./docs/typst_parsing_analysis.md)
62
+
63
+ ## ToDo
64
+
65
+ ## 📚 Citation
66
+
67
+ If you use this software in your research or writing, please cite it as follows:
68
+
69
+ ```bib
70
+ @software{korotenko-sci-trans-git,
71
+ author = {Yehor Korotenko},
72
+ title = {sci-trans-git},
73
+ year = {2025},
74
+ publisher = {GitHub},
75
+ version = {0.2.0-alpha},
76
+ url = {https://github.com/DobbiKov/sci-trans-git},
77
+ doi = {10.5281/zenodo.15775111}
78
+ }
79
+ ```
80
+
81
+ ## Contributing
82
+
83
+ The suggestions and pull requests are welcome. Visit the issues pages as well
84
+ as the project's [main page](https://github.com/DobbiKov/sci-trans-git) and the
85
+ [shared document](https://codimd.math.cnrs.fr/sUW9PQ1tTLWcR98UjLHLpw) in order
86
+ to know the current direction and plans of the project.
@@ -0,0 +1,81 @@
1
+ # Cache Clear Technical Report
2
+
3
+ ## Overview
4
+ This change adds cache clear behaviors:
5
+ - `translate-dir cache clear --missing-chunks` cleans the cache by removing or fixing correspondence entries that point to missing chunk files. It also removes orphaned source chunks that have no correspondence rows.
6
+ - `translate-dir cache clear --all --lang <language>` and/or `--file <path>` deletes cached data scoped to a specific language and/or file.
7
+ - `translate-dir cache clear --all --keyword <string>` deletes cached chunks whose contents include the keyword, with optional `--lang`/`--file` scoping.
8
+
9
+ ## Files and Components
10
+ - `src/trans_lib/translation_cache/cache_cleaner.py`
11
+ - Cleanup implementations.
12
+ - Exposes `clear_missing_chunks(root_path, source_lang)` and `clear_all(root_path, lang, relative_path)`.
13
+ - `src/trans_lib/project_runtime.py`
14
+ - Adds cache clear wrappers with error handling.
15
+ - `src/trans_lib/project_manager.py`
16
+ - Adds convenience methods for cache clear actions.
17
+ - `src/cli.py`
18
+ - Adds `translate-dir cache clear --missing-chunks` and `--all` CLI entry points.
19
+ - `src/trans_lib/errors.py`
20
+ - Adds `TranslationCacheClearError`.
21
+ - `tests/test_cache_clear.py`
22
+ - New coverage for row removal, field clearing, and orphan source deletion.
23
+
24
+ ## Cache Layout (used by cleanup)
25
+ The cleanup logic directly scans the on-disk cache and ignores `path_checksums.csv`.
26
+ - Cache root: `<project>/.translate_dir/translate_cache`
27
+ - Chunk files are stored by language and path checksum:
28
+ - `<lang>/<path_hash>/<chunk_checksum>`
29
+
30
+ ## Cleanup Algorithm (missing-chunks)
31
+ Inputs:
32
+ - Source language from project config.
33
+ - Correspondence CSV (`correspondence_cache.csv`) if present.
34
+ - On-disk chunk files.
35
+
36
+ Steps:
37
+ 1. Load cache root. If it does not exist, exit with zero changes.
38
+ 2. Enumerate all source language chunk files (including any that are stored directly under `<lang>/`).
39
+ 3. Load correspondence rows:
40
+ - If CSV does not exist: treat all source chunks as orphaned and delete them.
41
+ 4. For each row:
42
+ - Resolve `path_hash` and source checksum.
43
+ - If source checksum is missing or its chunk file is missing: remove the row.
44
+ - Otherwise, validate all target language checksum files:
45
+ - If at least one target chunk file exists, clear only missing target fields.
46
+ - If no target chunk files exist, remove the row.
47
+ 5. Write a new correspondence CSV if any row was removed or fields were cleared.
48
+ 6. Remove any source chunk files that are not referenced by a kept correspondence row.
49
+
50
+ ## Behavior Summary
51
+ - Rows with missing source files are removed.
52
+ - Rows with no existing target chunk files are removed.
53
+ - Rows with some missing targets are kept and the missing checksum fields are cleared.
54
+ - Orphaned source chunks (no correspondence row) are deleted.
55
+ - Target chunk files are deleted when they are not referenced by any remaining correspondence row.
56
+ - Keyword deletes only the matching chunk files and clears corresponding fields; rows are removed only when all language fields are empty.
57
+
58
+ ## CLI Usage
59
+ ```
60
+ translate-dir cache clear --missing-chunks
61
+ ```
62
+ ```
63
+ translate-dir cache clear --all --lang English
64
+ translate-dir cache clear --all --file src_en/doc.md
65
+ translate-dir cache clear --all --lang French --file src_en/doc.md
66
+ translate-dir cache clear --all
67
+ translate-dir cache clear --all --keyword glossary
68
+ translate-dir cache clear --all --file src_en/doc.md --keyword glossary
69
+ ```
70
+ The command requires at least one action flag. `--lang` and `--file` only work with `--all`. `--all` without scopes clears all cache and correspondence rows. It reports:
71
+ - removed rows
72
+ - cleared fields
73
+ - removed chunk files
74
+
75
+ ## Tests Added
76
+ - `test_clear_missing_chunks_removes_row_and_source`
77
+ - `test_clear_missing_chunks_clears_missing_target_fields`
78
+ - `test_clear_missing_chunks_removes_row_when_source_missing`
79
+ - `test_clear_missing_chunks_removes_orphan_source_chunks`
80
+
81
+ These tests validate row removal, field clearing, orphan removal, and the non-deletion of target chunk files.