unbabelizer 1.0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dawid Ciepiela
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,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: unbabelizer
3
+ Version: 1.0.0
4
+ Summary: A CLI tool to translate gettext .po files.
5
+ Author-email: Dawid Ciepiela <71898979+sarumaj@users.noreply.github.com>
6
+ License: MIT
7
+ Keywords: translation,google translate,po files
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: babel==2.17.0
15
+ Requires-Dist: googletrans==4.0.2
16
+ Requires-Dist: jmespath==1.0.1
17
+ Requires-Dist: polib==1.2.0
18
+ Requires-Dist: pydantic==2.11.9
19
+ Requires-Dist: textual==6.1.0
20
+ Dynamic: license-file
21
+
22
+ # unbabelizer
23
+
24
+ `unbabelizer` is an interactive CLI and TUI (Text User Interface) tool for
25
+ managing gettext `.po` translation files.
26
+ It streamlines the localization workflow for Python projects by automating
27
+ extraction, translation, review, and compilation of translation files.
28
+
29
+ ## Purpose
30
+
31
+ The main goal of `unbabelizer` is to simplify and automate the process of
32
+ internationalizing Python applications.
33
+ It provides a guided interface for developers and translators to:
34
+
35
+ - Extract translatable strings from source code.
36
+ - Automatically translate `.po` files using Google Translate.
37
+ - Review and edit translations interactively.
38
+ - Compile `.po` files into binary `.mo` files for deployment.
39
+ - Manage multiple languages and domains with ease.
40
+ - Integrate seamlessly with Babel and polib for robust gettext support.
41
+
42
+ ## Demo
43
+
44
+ [![Demo](docs/thumbnail.png)](https://youtu.be/lIy65BAJYbs)
45
+
46
+ The app is itself available in German language. Simply run
47
+
48
+ ```shell
49
+ LANG=de unbabelizer
50
+ ```
51
+
52
+ to execute the app in German language.
53
+
54
+ ## Features
55
+
56
+ - **Interactive TUI:** Edit and review translations in a modern terminal UI
57
+ powered by [Textual](https://github.com/Textualize/textual).
58
+ - **Automated Extraction:** Find and extract translatable strings from your
59
+ codebase using Babel.
60
+ - **Batch Translation:** Translate `.po` files automatically via Google Translate,
61
+ with support for multiple target languages.
62
+ - **Review Workflow:** Step through translations, edit entries, and mark reviewed
63
+ items.
64
+ - **Compilation:** Compile `.po` files to `.mo` for production use.
65
+ - **Configurable:** Control all aspects via `pyproject.toml` or CLI arguments.
66
+ - **Exclusion Patterns:** Skip files or directories using glob patterns.
67
+ - **Custom Mapping:** Provide custom Babel mapping for source file types.
68
+ - **Logging:** Detailed logging for troubleshooting and auditing translation changes.
69
+
70
+ ## Installation
71
+
72
+ You can install the package via pip:
73
+
74
+ ```shell
75
+ pip install unbabelizer
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ Execute in a directory with a `pyproject.toml` config file:
81
+
82
+ ```shell
83
+ unbabelizer
84
+ ```
85
+
86
+ The configuration section in `pyproject.toml` might look as follows:
87
+
88
+ ```toml
89
+ [tool.unbabelizer]
90
+ # List of destination languages (e.g., German)
91
+ dest_lang = ["de"]
92
+
93
+ # Paths to search for source files
94
+ input_paths = ["src"]
95
+
96
+ # Directory for locale files
97
+ locale_dir = "src/unbabelizer/locales"
98
+
99
+ # Source language code
100
+ src_lang = "en"
101
+
102
+ # Domain for the .po files (default: "messages")
103
+ domain = "messages"
104
+
105
+ # Patterns to exclude from searching (optional)
106
+ exclude_patterns = ["tests/*", "docs/*"]
107
+
108
+ # Content of the Babel mapping file (optional)
109
+ mapping_file_content = """
110
+ [python: **.py]
111
+ encoding = utf-8
112
+ """
113
+
114
+ # Line width for .po files (optional, default: 120)
115
+ line_width = 120
116
+ ```
117
+
118
+ You can also override these settings using CLI arguments:
119
+
120
+ ```shell
121
+ unbabelizer \
122
+ --dest-lang de \
123
+ --input-paths src \
124
+ --locale-dir src/unbabelizer/locales \
125
+ --src-lang en \
126
+ --domain messages \
127
+ --exclude-patterns tests/* docs/* \
128
+ --mapping-file "~/mapping_file.txt" \
129
+ --line-width 120
130
+ ```
131
+
132
+ - `--dest-lang`: Destination language(s) (repeat or use multiple values)
133
+ - `--input-paths`: Source file paths (repeat or use multiple values)
134
+ - `--locale-dir`: Locale directory
135
+ - `--src-lang`: Source language code
136
+ - `--domain`: .po file domain
137
+ - `--exclude-patterns`: Patterns to exclude (optional)
138
+ - `--mapping-file`: Babel mapping file (optional)
139
+ - `--line-width`: Line width for .po files (optional)
140
+
141
+ Settings from the CLI override those in `pyproject.toml`.
142
+
143
+ ## Contributing
144
+
145
+ Contributions are welcome! Please open an issue or submit a pull request.
146
+
147
+ ## License
148
+
149
+ This project is licensed under the MIT License.
@@ -0,0 +1,128 @@
1
+ # unbabelizer
2
+
3
+ `unbabelizer` is an interactive CLI and TUI (Text User Interface) tool for
4
+ managing gettext `.po` translation files.
5
+ It streamlines the localization workflow for Python projects by automating
6
+ extraction, translation, review, and compilation of translation files.
7
+
8
+ ## Purpose
9
+
10
+ The main goal of `unbabelizer` is to simplify and automate the process of
11
+ internationalizing Python applications.
12
+ It provides a guided interface for developers and translators to:
13
+
14
+ - Extract translatable strings from source code.
15
+ - Automatically translate `.po` files using Google Translate.
16
+ - Review and edit translations interactively.
17
+ - Compile `.po` files into binary `.mo` files for deployment.
18
+ - Manage multiple languages and domains with ease.
19
+ - Integrate seamlessly with Babel and polib for robust gettext support.
20
+
21
+ ## Demo
22
+
23
+ [![Demo](docs/thumbnail.png)](https://youtu.be/lIy65BAJYbs)
24
+
25
+ The app is itself available in German language. Simply run
26
+
27
+ ```shell
28
+ LANG=de unbabelizer
29
+ ```
30
+
31
+ to execute the app in German language.
32
+
33
+ ## Features
34
+
35
+ - **Interactive TUI:** Edit and review translations in a modern terminal UI
36
+ powered by [Textual](https://github.com/Textualize/textual).
37
+ - **Automated Extraction:** Find and extract translatable strings from your
38
+ codebase using Babel.
39
+ - **Batch Translation:** Translate `.po` files automatically via Google Translate,
40
+ with support for multiple target languages.
41
+ - **Review Workflow:** Step through translations, edit entries, and mark reviewed
42
+ items.
43
+ - **Compilation:** Compile `.po` files to `.mo` for production use.
44
+ - **Configurable:** Control all aspects via `pyproject.toml` or CLI arguments.
45
+ - **Exclusion Patterns:** Skip files or directories using glob patterns.
46
+ - **Custom Mapping:** Provide custom Babel mapping for source file types.
47
+ - **Logging:** Detailed logging for troubleshooting and auditing translation changes.
48
+
49
+ ## Installation
50
+
51
+ You can install the package via pip:
52
+
53
+ ```shell
54
+ pip install unbabelizer
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ Execute in a directory with a `pyproject.toml` config file:
60
+
61
+ ```shell
62
+ unbabelizer
63
+ ```
64
+
65
+ The configuration section in `pyproject.toml` might look as follows:
66
+
67
+ ```toml
68
+ [tool.unbabelizer]
69
+ # List of destination languages (e.g., German)
70
+ dest_lang = ["de"]
71
+
72
+ # Paths to search for source files
73
+ input_paths = ["src"]
74
+
75
+ # Directory for locale files
76
+ locale_dir = "src/unbabelizer/locales"
77
+
78
+ # Source language code
79
+ src_lang = "en"
80
+
81
+ # Domain for the .po files (default: "messages")
82
+ domain = "messages"
83
+
84
+ # Patterns to exclude from searching (optional)
85
+ exclude_patterns = ["tests/*", "docs/*"]
86
+
87
+ # Content of the Babel mapping file (optional)
88
+ mapping_file_content = """
89
+ [python: **.py]
90
+ encoding = utf-8
91
+ """
92
+
93
+ # Line width for .po files (optional, default: 120)
94
+ line_width = 120
95
+ ```
96
+
97
+ You can also override these settings using CLI arguments:
98
+
99
+ ```shell
100
+ unbabelizer \
101
+ --dest-lang de \
102
+ --input-paths src \
103
+ --locale-dir src/unbabelizer/locales \
104
+ --src-lang en \
105
+ --domain messages \
106
+ --exclude-patterns tests/* docs/* \
107
+ --mapping-file "~/mapping_file.txt" \
108
+ --line-width 120
109
+ ```
110
+
111
+ - `--dest-lang`: Destination language(s) (repeat or use multiple values)
112
+ - `--input-paths`: Source file paths (repeat or use multiple values)
113
+ - `--locale-dir`: Locale directory
114
+ - `--src-lang`: Source language code
115
+ - `--domain`: .po file domain
116
+ - `--exclude-patterns`: Patterns to exclude (optional)
117
+ - `--mapping-file`: Babel mapping file (optional)
118
+ - `--line-width`: Line width for .po files (optional)
119
+
120
+ Settings from the CLI override those in `pyproject.toml`.
121
+
122
+ ## Contributing
123
+
124
+ Contributions are welcome! Please open an issue or submit a pull request.
125
+
126
+ ## License
127
+
128
+ This project is licensed under the MIT License.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ build-backend = "setuptools.build_meta"
3
+ requires = ["setuptools", "wheel"]
4
+
5
+ [project]
6
+ authors = [
7
+ {name = "Dawid Ciepiela", email = "71898979+sarumaj@users.noreply.github.com"},
8
+ ]
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3.12",
11
+ "License :: OSI Approved :: MIT License",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ dependencies = [
15
+ "babel==2.17.0",
16
+ "googletrans==4.0.2",
17
+ "jmespath==1.0.1",
18
+ "polib==1.2.0",
19
+ "pydantic==2.11.9",
20
+ "textual==6.1.0",
21
+ ]
22
+ description = "A CLI tool to translate gettext .po files."
23
+ keywords = ["translation", "google translate", "po files"]
24
+ license = {text = "MIT"}
25
+ name = "unbabelizer"
26
+ readme = "README.md"
27
+ requires-python = ">=3.12"
28
+ scripts = {unbabelizer = "unbabelizer.__main__:main"}
29
+ version = "1.0.0"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.unbabelizer]
35
+ dest_lang = ["de"]
36
+ input_paths = ["src"]
37
+ locale_dir = "src/unbabelizer/locales"
38
+ src_lang = "en"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,292 @@
1
+ import asyncio
2
+ from enum import Enum
3
+ from gettext import gettext as _
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from textual import work
8
+ from textual.app import App, ComposeResult
9
+ from textual.binding import Binding
10
+ from textual.containers import Container
11
+ from textual.widgets import Footer, Header, ProgressBar, Select, SelectionList, Static
12
+
13
+ from .config import Config
14
+ from .log import Logger
15
+ from .modals.confirm_inevitable import ConfirmInevitable
16
+ from .modals.po_review_sc import POReviewScreen
17
+ from .modals.po_translation_sc import Translator
18
+ from .types import SubCommand
19
+ from .utils import NotifyException, apply_styles, run_babel_cmd, wait_for_element
20
+
21
+
22
+ class AppSubCommand(Enum):
23
+ EXTRACT_UPDATE = SubCommand("extract_update", _("Extract and Update"), False, True)
24
+ TRANSLATE = SubCommand("translate", _("Translate"), True, False)
25
+ REVIEW = SubCommand("review", _("Review"), True, True)
26
+ COMPILE = SubCommand("compile", _("Compile"), False, True)
27
+
28
+
29
+ class UnbabelizerApp(App[None]):
30
+ """The main application class for unbabelizer."""
31
+
32
+ BINDINGS = [
33
+ Binding(key="r", action="run_workflow", description=_("Run Workflow"), show=True),
34
+ Binding(key="q", action="quit", description=_("Quit"), show=True),
35
+ Binding(key="c", action="clear", description=_("Clear translation files"), show=True),
36
+ ]
37
+
38
+ def __init__(self, config: Config):
39
+ """Initialize the unbabelizerApp with the given configuration.
40
+
41
+ Args:
42
+ config (Config): The configuration for the application.
43
+ """
44
+ super().__init__()
45
+ self._app_logger = Logger()
46
+ self._config = config
47
+ self._config.locale_dir.mkdir(parents=True, exist_ok=True)
48
+ self._lock = asyncio.Lock()
49
+ self._current_lang_idx = 0
50
+ self.logger.debug(
51
+ "unbabelizerApp initialized with config:", extra={"config": self._config, "context": "unbabelizerApp.init"}
52
+ )
53
+
54
+ @property
55
+ def logger(self) -> Logger:
56
+ """Return the application logger."""
57
+ return self._app_logger
58
+
59
+ @property
60
+ def potfile_path(self) -> Path:
61
+ """Path to the .pot file."""
62
+ return self._config.locale_dir / "base.pot"
63
+
64
+ @property
65
+ def pofile_path(self) -> Path:
66
+ """Path to the .po file for the target language."""
67
+ return (
68
+ self._config.locale_dir
69
+ / self._config.dest_lang[self._current_lang_idx]
70
+ / "LC_MESSAGES"
71
+ / f"{self._config.domain}.po"
72
+ )
73
+
74
+ def compose(self) -> ComposeResult:
75
+ """Compose the UI elements for the main application."""
76
+ yield Header()
77
+ yield apply_styles(
78
+ Container(
79
+ Static(_("Target language")),
80
+ Select(
81
+ [(l, l) for l in self._config.dest_lang],
82
+ prompt=_("Select target language"),
83
+ value=self._config.dest_lang[self._current_lang_idx],
84
+ ),
85
+ Static(_("Translation Workflow")),
86
+ SelectionList(
87
+ AppSubCommand.EXTRACT_UPDATE.value.selection_list_item,
88
+ AppSubCommand.TRANSLATE.value.selection_list_item,
89
+ AppSubCommand.REVIEW.value.selection_list_item,
90
+ AppSubCommand.COMPILE.value.selection_list_item,
91
+ ),
92
+ apply_styles(
93
+ ProgressBar(total=100, show_eta=True, show_percentage=True),
94
+ vertical="bottom",
95
+ width="1fr",
96
+ height="1fr",
97
+ ),
98
+ ),
99
+ vertical="top",
100
+ width="1fr",
101
+ height="1fr",
102
+ )
103
+ yield Footer()
104
+
105
+ async def on_mount(self):
106
+ """Handle the mount event for the application."""
107
+ (await wait_for_element(self.query_one, selector=SelectionList)).focus()
108
+
109
+ async def on_select_changed(self, message: Select.Changed):
110
+ """Handle changes to the target language selection."""
111
+ if message.value not in self._config.dest_lang:
112
+ self.logger.warning(
113
+ "Selected language not in configured destination languages",
114
+ extra={"selected_language": message.value, "context": "unbabelizerApp.on_select_changed"},
115
+ )
116
+ return
117
+
118
+ self._current_lang_idx = self._config.dest_lang.index(f"{message.value}")
119
+ self.logger.info(
120
+ "Target language changed",
121
+ extra={
122
+ "new_language": self._config.dest_lang[self._current_lang_idx],
123
+ "context": "unbabelizerApp.on_select_changed",
124
+ },
125
+ )
126
+
127
+ async def action_clear(self):
128
+ """Clear all .po and .mo files in the locale directory."""
129
+
130
+ def callback(result: Any):
131
+ if result is not True:
132
+ return
133
+
134
+ self.logger.info("Clearing translation files...", extra={"context": "unbabelizerApp.clear"})
135
+ with NotifyException(self):
136
+ for path in self._config.locale_dir.rglob("*"):
137
+ if path.is_file():
138
+ self.logger.debug("Removing file", extra={"path": path, "context": "unbabelizerApp.clear"})
139
+ path.unlink()
140
+
141
+ for path in self._config.locale_dir.rglob("*"):
142
+ if path.is_dir() and not any(path.iterdir()):
143
+ self.logger.debug(
144
+ "Removing empty directory", extra={"path": path, "context": "unbabelizerApp.clear"}
145
+ )
146
+ path.rmdir()
147
+
148
+ self.notify(_("All translation files cleared."), timeout=3, title=_("✅ Success"))
149
+ self.logger.info("Translation files cleared.", extra={"context": "unbabelizerApp.clear"})
150
+
151
+ await self.push_screen(ConfirmInevitable(), callback=callback)
152
+
153
+ async def action_run_workflow(self):
154
+ """Run the selected workflow actions."""
155
+ self.logger.info("Running workflow actions...", extra={"context": "unbabelizerApp.run_workflow"})
156
+ selection_list = await wait_for_element(self.query_one, selector=SelectionList)
157
+ selections = [f"{option}" for option in selection_list.selected]
158
+ self.logger.debug(
159
+ "Selected actions:", extra={"selections": selections, "context": "unbabelizerApp.run_workflow"}
160
+ )
161
+ progress_bar = await wait_for_element(self.query_one, selector=ProgressBar)
162
+ progress_bar.update(total=100, progress=0)
163
+ actions = {
164
+ AppSubCommand.EXTRACT_UPDATE.value.name: self.flow_extract_and_update,
165
+ AppSubCommand.TRANSLATE.value.name: self.flow_translate_pofile,
166
+ AppSubCommand.REVIEW.value.name: self.flow_review_pofile,
167
+ AppSubCommand.COMPILE.value.name: self.flow_compile_translations,
168
+ }
169
+ for action in actions:
170
+ if action in selections:
171
+ self.logger.info(f"Starting action: {action}", extra={"context": "unbabelizerApp.run_workflow"})
172
+ actions[action]()
173
+ progress_bar.advance(100 // (len(selections) or 1))
174
+
175
+ progress_bar.update(total=100, progress=100)
176
+
177
+ async def action_quit(self):
178
+ """Quit the application."""
179
+ self.logger.info("Quitting application...", extra={"context": "unbabelizerApp.quit"})
180
+ self.exit()
181
+
182
+ @work(group="main")
183
+ async def flow_extract_and_update(self):
184
+ """Extract messages and update or initiate .po files."""
185
+ self.logger.info(
186
+ "Extracting and updating translations...", extra={"context": "unbabelizerApp.flow_extract_and_update"}
187
+ )
188
+ await self._lock.acquire()
189
+
190
+ # Extraction (overwrite existing .pot file)
191
+ mapping_file = self._config.locale_dir / "babel_mapping.txt"
192
+ self.logger.debug(
193
+ "Creating temporary Babel mapping file",
194
+ extra={"path": mapping_file, "context": "unbabelizerApp.flow_extract_and_update"},
195
+ )
196
+ mapping_file.touch()
197
+ mapping_file.write_text(self._config.mapping_file.strip() + "\n")
198
+ self.logger.debug(
199
+ "Babel mapping file content:",
200
+ extra={"content": mapping_file.read_text(), "context": "unbabelizerApp.flow_extract_and_update"},
201
+ )
202
+
203
+ self.logger.debug(
204
+ "Running Babel extract command",
205
+ extra={"context": "unbabelizerApp.flow_extract_and_update"},
206
+ )
207
+ run_babel_cmd(
208
+ ["extract"]
209
+ + ["--project", self._config.title]
210
+ + ["--version", self._config.version]
211
+ + ["--copyright-holder", self._config.author]
212
+ + ["--last-translator", self._config.email]
213
+ + ["--no-location"]
214
+ + ["--sort-output"]
215
+ + ["-F", str(mapping_file.resolve())]
216
+ + ["-o", str(self.potfile_path)]
217
+ + ["--ignore-dirs", *(ex for ex in self._config.exclude_patterns)]
218
+ + ["--input-paths", *(str(i.resolve()) for i in self._config.input_paths)]
219
+ )
220
+ mapping_file.unlink()
221
+
222
+ if self.pofile_path.exists():
223
+ self.logger.debug(
224
+ "Updating existing .po file",
225
+ extra={"path": self.pofile_path, "context": "unbabelizerApp.flow_extract_and_update"},
226
+ )
227
+ # Update existing .po file
228
+ run_babel_cmd(
229
+ ["update"]
230
+ + ["-D", self._config.domain]
231
+ + ["-i", str(self.potfile_path)]
232
+ + ["-d", str(self._config.locale_dir)]
233
+ + ["-l", self._config.dest_lang[self._current_lang_idx]]
234
+ + ["-w", str(self._config.line_width)]
235
+ + ["--init-missing"]
236
+ )
237
+ else:
238
+ self.logger.debug(
239
+ "Creating new .po file",
240
+ extra={"path": self.pofile_path, "context": "unbabelizerApp.flow_extract_and_update"},
241
+ )
242
+ # Initialize new .po file
243
+ run_babel_cmd(
244
+ ["init"]
245
+ + ["-i", str(self.potfile_path)]
246
+ + ["-d", str(self._config.locale_dir)]
247
+ + ["-l", self._config.dest_lang[self._current_lang_idx]]
248
+ + ["-w", str(self._config.line_width)]
249
+ + ["-D", self._config.domain]
250
+ )
251
+ self.logger.info(
252
+ "Extraction and update completed.",
253
+ extra={
254
+ "pot_path": self.potfile_path,
255
+ "po_path": self.pofile_path,
256
+ "context": "unbabelizerApp.flow_extract_and_update",
257
+ },
258
+ )
259
+ self._lock.release()
260
+ self.notify(_("Extraction and update completed."), timeout=3, title=_("✅ Success"))
261
+
262
+ @work(group="main")
263
+ async def flow_compile_translations(self):
264
+ """Compile .po files into .mo files."""
265
+ self.logger.info("Compiling translations...", extra={"context": "unbabelizerApp.flow_compile_translations"})
266
+ await self._lock.acquire()
267
+ run_babel_cmd(["compile"] + ["-D", self._config.domain] + ["-d", str(self._config.locale_dir)])
268
+ self._lock.release()
269
+ self.logger.info("Compilation completed.", extra={"context": "unbabelizerApp.flow_compile_translations"})
270
+ self.notify(_("Compilation completed."), timeout=3, title=_("✅ Success"))
271
+
272
+ @work(group="main")
273
+ async def flow_translate_pofile(self):
274
+ """Translate the .po file using Google Translate."""
275
+ self.logger.info("Pushing translation screen", extra={"context": "unbabelizerApp.flow_translate_po"})
276
+ await self._lock.acquire()
277
+ await self.push_screen(
278
+ Translator(self.pofile_path, self._config.src_lang, self._config.dest_lang[self._current_lang_idx]),
279
+ callback=lambda _: self._lock.release(),
280
+ )
281
+ self.logger.info("Translation screen pushed", extra={"context": "unbabelizerApp.flow_translate_po"})
282
+
283
+ @work(group="main")
284
+ async def flow_review_pofile(self):
285
+ """Review and edit the .po file."""
286
+ self.logger.info("Pushing PO review screen", extra={"context": "unbabelizerApp.flow_review_po"})
287
+ await self._lock.acquire()
288
+ await self.push_screen(
289
+ POReviewScreen(self.pofile_path),
290
+ callback=lambda _: self._lock.release(),
291
+ )
292
+ self.logger.info("PO review screen dismissed", extra={"context": "unbabelizerApp.flow_review_po"})
@@ -0,0 +1,32 @@
1
+ import gettext
2
+ import sys
3
+ import traceback
4
+ from gettext import gettext as _
5
+ from pathlib import Path
6
+
7
+ gettext.bindtextdomain(
8
+ "messages",
9
+ (Path(__file__).parent / "locales").resolve(),
10
+ )
11
+
12
+
13
+ from .app import UnbabelizerApp
14
+ from .config import Config, logger
15
+
16
+
17
+ def main(args: list[str] | None = None):
18
+ """Entry point for the unbabelizer CLI application."""
19
+ try:
20
+ config = Config.build(args)
21
+ logger.info("Running unbabelizerApp with config:", extra={"context": "cli.main", "config": config})
22
+ app = UnbabelizerApp(config)
23
+ logger.info("Starting unbabelizerApp...")
24
+ app.run()
25
+ logger.info("unbabelizerApp has terminated gracefully.")
26
+ except Exception as e:
27
+ logger.error(
28
+ "An unhandled exception occurred: %s",
29
+ str(e),
30
+ extra={"context": "cli.main", "trace": traceback.format_exc()},
31
+ )
32
+ sys.exit(1)