MCPcopy
hub / github.com/django/django / write_po_file

Method write_po_file

django/core/management/commands/makemessages.py:702–745  ·  view source on GitHub ↗

Create or update the PO file for self.domain and `locale`. Use contents of the existing `potfile`. Use msgmerge and msgattrib GNU gettext utilities.

(self, potfile, locale)

Source from the content-addressed store, hash-verified

700 build_file.cleanup()
701
702 def write_po_file(self, potfile, locale):
703 """
704 Create or update the PO file for self.domain and `locale`.
705 Use contents of the existing `potfile`.
706
707 Use msgmerge and msgattrib GNU gettext utilities.
708 """
709 basedir = os.path.join(os.path.dirname(potfile), locale, "LC_MESSAGES")
710 os.makedirs(basedir, exist_ok=True)
711 pofile = os.path.join(basedir, "%s.po" % self.domain)
712
713 if os.path.exists(pofile):
714 args = ["msgmerge", *self.msgmerge_options, pofile, potfile]
715 _, errors, status = popen_wrapper(args)
716 if errors:
717 if status != STATUS_OK:
718 raise CommandError(
719 "errors happened while running msgmerge\n%s" % errors
720 )
721 elif self.verbosity > 0:
722 self.stdout.write(errors)
723 msgs = Path(pofile).read_text(encoding="utf-8")
724 else:
725 with open(potfile, encoding="utf-8") as fp:
726 msgs = fp.read()
727 if not self.invoked_for_django:
728 msgs = self.copy_plural_forms(msgs, locale)
729 msgs = normalize_eols(msgs)
730 msgs = msgs.replace(
731 "#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % self.domain, ""
732 )
733 with open(pofile, "w", encoding="utf-8") as fp:
734 fp.write(msgs)
735
736 if self.no_obsolete:
737 args = ["msgattrib", *self.msgattrib_options, "-o", pofile, pofile]
738 msgs, errors, status = popen_wrapper(args)
739 if errors:
740 if status != STATUS_OK:
741 raise CommandError(
742 "errors happened while running msgattrib\n%s" % errors
743 )
744 elif self.verbosity > 0:
745 self.stdout.write(errors)
746
747 def copy_plural_forms(self, msgs, locale):
748 """

Callers 1

handleMethod · 0.95

Calls 8

copy_plural_formsMethod · 0.95
popen_wrapperFunction · 0.90
CommandErrorClass · 0.90
normalize_eolsFunction · 0.85
joinMethod · 0.45
existsMethod · 0.45
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected