Compile PO Translation Files to MO Format
The bench compile-po-to-mo command converts human-readable PO translation files into binary MO files that can be used by the application. These compiled files are stored inside the bench assets directory and are loaded during runtime for translations.
Prerequisites
Before running this command, make sure your application contains existing .po translation files inside the app’s locale directory for at least one language.
Usage
bench compile-po-to-mo [OPTIONS]
What This Command Does
The PO files store translations in a human-readable format. However, applications use compiled binary MO files for faster loading and better runtime performance.
The bench compile-po-to-mo command performs the following actions:
- Reads translation data from existing
.pofiles. - Compiles PO files into binary
.mofiles. - Stores compiled files inside the
sites/assets/localedirectory. - Skips compilation when an existing MO file is newer than its related PO file.
This command is automatically executed during bench build and bench update. You can also run it manually in a development environment after adding new translations to immediately test them in the application UI.
Available Options
| Option | Description |
|---|---|
--app |
Compiles translation files for a specific application only. If not provided, all installed applications are processed. |
--locale |
Compiles translation files for a specific language or locale only. If not provided, all available locales are compiled. |
--force |
Forces recompilation even when the PO files have not changed or existing MO files are already updated. |
Example
Compile ERPNext’s German translation files:
bench compile-po-to-mo --app erpnext --locale de
This command reads the German PO translation file:
apps/erpnext/erpnext/locale/de.po
It then compiles the translation into a binary MO file and saves the output at:
sites/assets/locale/de/LC_MESSAGES/erpnext.mo
Best Practice
Run bench compile-po-to-mo after adding or modifying translations in your development environment. This allows you to verify updated language changes directly in the application interface without waiting for a full build process.