def write_po_files(
        self,
        legal_code,
        language_code,
        english_by_unit_version,
        messages_text,
    ):
        tool = legal_code.tool
        unit = tool.unit
        version = tool.version
        po_filename = legal_code.translation_filename()
        transifex_language = map_django_to_transifex_language_code(
            language_code)

        key = f"{unit}|{version}"
        english_messages = english_by_unit_version[key]

        pofile = POFile()
        # The syntax used to wrap messages in a .po file is
        # difficult if you ever want to copy/paste the messages, so
        # if --unwrapped was passed, set a wrap width that will
        # essentially disable wrapping.
        if self.unwrapped:
            pofile.wrapwidth = 999999

        # Use the English message text as the message key
        for internal_key, translation in messages_text.items():
            message_key = english_messages[internal_key]
            message_value = translation

            pofile.append(
                POEntry(
                    msgid=clean_string(message_key),
                    msgstr=clean_string(message_value),
                ))
        # https://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html  # noqa: E501
        pofile.metadata = {
            "Content-Transfer-Encoding": "8bit",
            "Content-Type": "text/plain; charset=utf-8",
            "Language": transifex_language,
            "Language-Django": language_code,
            "Language-Transifex": transifex_language,
            "Language-Team": "https://www.transifex.com/creativecommons/CC/",
            "MIME-Version": "1.0",
            "PO-Revision-Date": NOW,
            "Percent-Translated": pofile.percent_translated(),
            "Project-Id-Version": legal_code.tool.resource_slug,
        }

        directory = os.path.dirname(po_filename)
        if not os.path.isdir(directory):
            os.makedirs(directory)
        # Save mofile ourself. We could call 'compilemessages' but
        # it wants to compile everything, which is both overkill
        # and can fail if the venv or project source is not
        # writable. We know this dir is writable, so just save this
        # pofile and mofile ourselves.
        LOG.debug(f"Writing {po_filename.replace('.po', '')}.(mo|po)")
        save_pofile_as_pofile_and_mofile(pofile, po_filename)