Internationalization¶
This page documents how to manage translation catalogs for the plugin (Python and JavaScript strings) and the typical pybabel workflow used in this repository.
Locations¶
- Python templates and code:
octoprint_uptime/translations/(contains locale subfolders withLC_MESSAGES/messages.poand compiled.mo). - Project-level translations (used for packaging/documentation): top-level
translations/(also containsdeandenlocale folders).
Basic workflow (recommended, run from project root)¶
- Extract translatable strings into a POT file:
# using the venv-binary if you have a project virtualenv
./venv/bin/pybabel extract -F babel.cfg -o translations/messages.pot .
- Update each language catalog from the new POT:
./venv/bin/pybabel update -i translations/messages.pot -d octoprint_uptime/translations
./venv/bin/pybabel update -i translations/messages.pot -d translations
-
Edit the
.pofiles in the respectiveLC_MESSAGESfolders and add translations. -
Compile
.pointo binary.mofiles for runtime use:
./venv/bin/pybabel compile -d octoprint_uptime/translations
./venv/bin/pybabel compile -d translations
Notes and tips¶
- JavaScript extraction: ensure JSDoc or gettext calls in JS are discoverable by your
babel.cfg. In this project,scripts/generate-jsdocs.shgeneratesdocs/api/javascript.md(not committed). JS gettext strings should be included inpybabel extractif configured inbabel.cfg. - Fuzzy entries: When merging new POTs you may find
#, fuzzyflags. Review and removefuzzyfrom entries that are correct, and translate the rest. - Obsolete entries (
#~): These are removed when you update catalogs from a fresh POT; review before deleting if you want to keep historical context. - Testing: After compiling, test the plugin in a development OctoPrint instance and check that localized strings appear in the UI and that the
.mofiles are present inoctoprint_uptime/translations/<lang>/LC_MESSAGES/messages.mo.
Troubleshooting¶
- If
pybabelisn't installed in your environment runpip install Babelor install into the project virtualenv used by development. - If compiled
.mofiles are not loaded at runtime, confirm the plugin package includes thetranslationsdirectory (checkMANIFEST.inand packaging config).