|
| 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) |
0 commit comments