Skip to main content

BuildFile

Represent the state of a translatable file during the build process.

Attributes

AttributeTypeDescription
command[Command](../testserver/command.md?sid=django_core_management_commands_testserver_command)The command instance responsible for managing the current translation build process.
domainstringThe translation domain, such as 'django' or 'djangojs', used to determine how the file is processed.
translatable[TranslatableFile](translatablefile.md?sid=django_core_management_commands_makemessages_translatablefile)An object representing the source file metadata, including its original path and filename.
is_templatizedbooleanIndicates whether the file requires preprocessing based on its domain and file extension.
pathstringThe filesystem path to the original translatable source file.
work_pathstringPath to a file which is being fed into GNU gettext pipeline. This may be either a translatable or its preprocessed version.

Constructor

Signature

def BuildFile(
command: Any,
domain: str,
translatable: Any
)

Parameters

NameTypeDescription
commandAnyThe command associated with the build process.
domainstrThe translation domain (e.g., 'django').
translatableAnyThe translatable file object containing path and file information.

Methods


is_templatized()

@classmethod
def is_templatized() - > boolean

Determines if the file requires template processing based on its domain and file extension.

Returns

TypeDescription
booleanTrue if the file is a Django template (non-Python file), False otherwise

path()

@classmethod
def path() - > string

Retrieves the original filesystem path of the translatable file.

Returns

TypeDescription
stringThe absolute or relative path to the source translatable file

work_path()

@classmethod
def work_path() - > string

Path to a file which is being fed into GNU gettext pipeline. This may be either a translatable or its preprocessed version.

Returns

TypeDescription
stringThe filesystem path used during the extraction process, pointing to either the original file or a generated .py version

preprocess()

@classmethod
def preprocess()

Preprocess (if necessary) a translatable file before passing it to xgettext GNU gettext utility.


postprocess_messages()

@classmethod
def postprocess_messages(
msgs: string
) - > string

Postprocess messages generated by xgettext GNU gettext utility. Transform paths as if these messages were generated from original translatable files rather than from preprocessed versions.

Parameters

NameTypeDescription
msgsstringThe raw message string output from the xgettext utility containing file location comments

Returns

TypeDescription
stringThe modified message string with file references updated to point to the original source files

cleanup()

@classmethod
def cleanup()

Remove a preprocessed copy of a translatable file (if any).