Skip to content

Commit 48a1141

Browse files
committed
Separate out i18n tasks
1 parent a4e3488 commit 48a1141

File tree

3 files changed

+59
-34
lines changed

3 files changed

+59
-34
lines changed

Makefile

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,6 @@ test_webui: venv
6868
coverage: venv
6969
PYTHONPATH=. $(VENV)/python test/coverage.py
7070

71-
#############################################################################
72-
## i18n
73-
74-
.PHONY: i18n-extract
75-
i18n-extract: venv
76-
PYTHONPATH=. $(VENV)/pybabel extract --omit-header --ignore-dirs="build dist .venv" -F tools/i18n/babel.cfg -o redbot/translations/messages.pot .
77-
78-
.PHONY: i18n-update
79-
i18n-update: i18n-extract venv
80-
$(VENV)/pybabel update -i redbot/translations/messages.pot -d redbot/translations
81-
82-
.PHONY: i18n-autotranslate
83-
i18n-autotranslate: venv
84-
$(VENV)/python -m tools.i18n.autotranslate --locale_dir redbot/translations --model $(or $(MODEL), 'mlx-community/aya-23-8B-4bit') #--rpm $(or $(RPM),10)
85-
86-
.PHONY: i18n-compile
87-
i18n-compile: venv
88-
$(VENV)/pybabel compile -d redbot/translations
89-
90-
.PHONY: translations
91-
translations: i18n-update i18n-compile
92-
93-
.PHONY: i18n-check
94-
i18n-check: venv
95-
PYTHONPATH=. $(VENV)/python -m tools.i18n.check
96-
97-
.PHONY: i18n-init
98-
i18n-init: venv
99-
@if [ -z "$(LOCALE)" ]; then echo "Usage: make init_locale LOCALE=xx"; exit 1; fi
100-
$(VENV)/pybabel init -i redbot/translations/messages.pot -d redbot/translations -l $(LOCALE)
101-
10271
#############################################################################
10372
## Local test server / cli
10473

@@ -145,3 +114,4 @@ $(MODULES):
145114

146115

147116
include Makefile.pyproject
117+
include Makefile.i18n

Makefile.i18n

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# i18n management for Python projects
3+
#
4+
# This file contains targets for managing translations and message catalogs.
5+
#
6+
# Recommended Workflow for updating translations:
7+
# 1. make i18n-extract - Extract source strings into messages.pot
8+
# 2. make i18n-update - Update existing PO files with new strings from POT
9+
# 3. make i18n-autotranslate - Use LLM to translate missing strings
10+
# 4. make i18n-compile - Compile PO files into MO binary files for runtime
11+
#
12+
# Shortcut: 'make translations' runs i18n-update followed by i18n-compile.
13+
#
14+
# Other targets:
15+
# - make i18n-check - Verify translation health (missing strings, variable mismatches)
16+
# - make i18n-init LOCALE=xx - Initialize a new translation catalog for a new language
17+
#
18+
19+
#############################################################################
20+
## i18n
21+
22+
.PHONY: venv-i18n
23+
venv-i18n: $(VENV)/$(MARKER)-i18n
24+
$(VENV)/$(MARKER)-i18n: $(VENV)/$(MARKER)
25+
$(VENV)/pip install -e .[i18n]
26+
touch $@
27+
28+
.PHONY: i18n-extract
29+
i18n-extract: venv-i18n
30+
PYTHONPATH=. $(VENV)/pybabel extract --omit-header --ignore-dirs="build dist .venv" -F tools/i18n/babel.cfg -o redbot/translations/messages.pot .
31+
32+
.PHONY: i18n-update
33+
i18n-update: i18n-extract venv-i18n
34+
$(VENV)/pybabel update -i redbot/translations/messages.pot -d redbot/translations
35+
36+
.PHONY: i18n-autotranslate
37+
i18n-autotranslate: venv-i18n
38+
$(VENV)/python -m tools.i18n.autotranslate --locale_dir redbot/translations --model $(or $(MODEL), 'mlx-community/aya-23-8B-4bit') #--rpm $(or $(RPM),10)
39+
40+
.PHONY: i18n-compile
41+
i18n-compile: venv-i18n
42+
$(VENV)/pybabel compile -d redbot/translations
43+
44+
.PHONY: translations
45+
translations: i18n-update i18n-compile
46+
47+
.PHONY: i18n-check
48+
i18n-check: venv-i18n
49+
PYTHONPATH=. $(VENV)/python -m tools.i18n.check
50+
51+
.PHONY: i18n-init
52+
i18n-init: venv-i18n
53+
@if [ -z "$(LOCALE)" ]; then echo "Usage: make init_locale LOCALE=xx"; exit 1; fi
54+
$(VENV)/pybabel init -i redbot/translations/messages.pot -d redbot/translations -l $(LOCALE)

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ dependencies = [
2828
"netaddr >= 1.2.1",
2929
"thor >= 0.12.5",
3030
"typing-extensions >= 4.8.0",
31-
"Babel >= 2.14.0",
3231
]
3332

3433
[project.urls]
@@ -45,10 +44,12 @@ dev = ["mypy",
4544
"build",
4645
"playwright",
4746
"types-Markdown",
48-
"llm",
49-
"llm-mlx",
5047
"j2lint",
5148
]
49+
i18n = ["Babel >= 2.14.0",
50+
"llm",
51+
"llm-mlx",
52+
]
5253

5354
[project.scripts]
5455
redbot = "redbot.cli:main"

0 commit comments

Comments
 (0)