Command
This class compiles .po message files into binary .mo files for use with builtin gettext support. It provides functionality to filter processing by specific locales, exclude directories, and include fuzzy translations using the GNU gettext toolset. The class automatically discovers locale directories within a project and handles concurrent file compilation while checking for file updates and encoding requirements.
Attributes
| Attribute | Type | Description |
|---|---|---|
| help | string = "Compiles .po files to .mo files for use with builtin gettext support." | Compiles .po files to .mo files for use with builtin gettext support. |
| requires_system_checks | list = [] | A list of system checks that must be performed before the command is executed, which is empty for this command. |
| program | string = "msgfmt" | The name of the executable used to compile message catalogs, defaulting to the GNU gettext 'msgfmt' utility. |
| program_options | list = ["--check-format"] | A list of command-line arguments passed to the compilation program to control its behavior during execution. |
Methods
add_arguments()
@classmethod
def add_arguments(
parser: [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser)
)
Configures the command line argument parser with options for filtering locales, ignoring paths, and enabling fuzzy translation support.
Parameters
| Name | Type | Description |
|---|---|---|
| parser | [CommandParser](../../base/commandparser.md?sid=django_core_management_base_commandparser) | The argument parser instance to which the locale, exclude, fuzzy, and ignore arguments will be added. |
handle()
@classmethod
def handle(
**options: dict
)
Executes the command logic by identifying relevant locale directories and initiating the compilation of .po files into .mo files.
Parameters
| Name | Type | Description |
|---|---|---|
| **options | dict | A dictionary of parsed command line arguments including 'locale', 'exclude', 'fuzzy', and 'ignore_patterns'. |
compile_messages()
@classmethod
def compile_messages(
locations: list
)
Locations is a list of tuples: [(directory, file), ...]
Parameters
| Name | Type | Description |
|---|---|---|
| locations | list | A list of tuples where each tuple contains the directory path and the filename of a .po file to be compiled. |