Skip to main content

pre-commit hooks for PO files

Project description


PyPI Python versions License Tests

Hooks for pre-commit useful working with PO files.

Example configuration

- repo:
  rev: v1.0.0
    - id: obsolete-messages
    - id: untranslated-messages
    - id: remove-django-translators
    - id: check-metadata
        - -h
        - Project-Id-Version
        - -v
        - v\d+\.\d+\.\d+



Checks for obsolete messages printing their line numbers if found.


Checks for untranslated messages printing their line numbers if found.


Replaces a matching string at the beginning of extracted comments.


  • -m/--match "STRING": Matching string to be replaced.
  • -r/--replacement "STRING": Replacement for the match at the beginning of the extracted comment. If you want to remove the matching beginning you can pass an empty string "".
  • -d/--dry-run: Don't do the replacements, only writes to stderr the locations of the extracted comments to be replaced.


Same as lreplace-extracted-comments passing --match "Translators: " --replacement "". Useful to remove the string prepended by Django extracting messages with xgettext (see more about this problem in django-rosetta#245).


Check that metadata fields matches a set of regular expressions.


  • -h/--header HEADER: Header name to match in metadata. This argument can be passed multiple times, but after each -h/--header argument must be a -v/--value that indicates the regular expression for that header.
  • -v/--value REGEX: Can be passed multiple times. Indicates the regular expression that the last header passed in the argument -h/--header must match in the checked PO files.
  • -n/--no-metadata: When this option is passed, the hook instead checks that there is no metadata in the files, so it will exit with code 1 if some metadata is found in a file or 0 if there is no metadata in any files.


Check that the metadata of your PO files fits some standard requirements based on the next regular expressions:

  • Project-Id-Version: \d+\.\d+\.\d
  • Report-Msgid-Bugs-To: .+\s<.+@.+\..+>
  • Last-Translator: .+\s<.+@.+\..+>
  • Language-Team: .+\s<.+@.+\..+>
  • Language: \w\w_?\w?\w?(@\w+)?
  • Content-Type: text/plain; charset=[a-zA-Z\-]+
  • Content-Transfer-Encoding: \d+bits?

If you need to replace some fields with other regular expressions, you can do it passing the -h and -v arguments of the check-metadata hook.

For example, if your version includes the character v at the beginning: -h "Project-Id-Version" -v "v\d+\.\d+\.\d"

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pre_commit_po_hooks-1.3.2.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

pre_commit_po_hooks-1.3.2-py2.py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page