Skip to main content

pre-commit hooks for PO files

Project description

pre-commit-po-hooks

PyPI Python versions License Tests

Hooks for pre-commit useful working with PO files.

Example configuration

- repo: https://github.com/mondeja/pre-commit-po-hooks
  rev: v1.6.1
  hooks:
    - id: obsolete-messages
    - id: untranslated-messages
    - id: remove-django-translators
    - id: standard-metadata
    - id: max-lines
      args: ["10000"]

Hooks

obsolete-messages

Checks for obsolete messages printing their line numbers if found.

untranslated-messages

Checks for untranslated messages printing their line numbers if found.

Parameters

  • -m/--min: Minimum number of messages that must be translated in each file to pass this check. Can be defined as a percentage of the messages translated appending a character % at the end of the value.

lreplace-extracted-comments

Replaces a matching string at the beginning of extracted comments.

Parameters

  • -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.

remove-django-translators

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-metadata

Check that metadata fields matches a set of regular expressions.

Parameters

  • -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.
  • -r/--remove/--remove-metadata: When this option is passed the metadata will be removed from the files instead of being treated as a lint error.

standard-metadata

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=[0-9a-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"

no-metadata

It will check if PO files has metadata. If has metadata, it will fail the check returning exit code 1.

Parameters

  • -r/--remove/--remove-metadata: When this option is passed the metadata will be removed from the files instead of being treated as a lint error.

remove-metadata

Remove metadata headers from your PO files. This is an alias for no-metadata hook passing --remove-metadata argument.

max-messages

Define a maximum number of entries for each PO file. Pass an interger in the first argument:

- id: max-messages
  args:
    - "5000"

Parameters

  • Maximum number of messages allowed for each PO file.

max-lines

Define a maximum number of lines for each PO file. Pass an interger in the first argument:

- id: max-lines
  args:
    - "10000"

Parameters

  • Maximum number of lines allowed for each PO file.

min-translated

Define a minimum number of files that must be translated in order to pass. Pass a float or a value ending with % character if you wan to compare against the percentage of translated files:

- id: min-translated
  args:
    - "95%"

Parameters

  • Minimum number or percentage of messages which must be translated in each PO file.

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.6.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pre_commit_po_hooks-1.6.1-py2.py3-none-any.whl (12.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pre_commit_po_hooks-1.6.1.tar.gz.

File metadata

  • Download URL: pre_commit_po_hooks-1.6.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pre_commit_po_hooks-1.6.1.tar.gz
Algorithm Hash digest
SHA256 8b7767be7da044db19abf837ab1da31bbafb12a2dcba030033b933a311624e51
MD5 52af924c1ab295665309f366ca3bc774
BLAKE2b-256 deef33b3ff86318aa02166b3b5381acb8c713cb22bc848a35c5556fe43cb38ce

See more details on using hashes here.

File details

Details for the file pre_commit_po_hooks-1.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pre_commit_po_hooks-1.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pre_commit_po_hooks-1.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce4b04ff8c9e85641b242d07f607ffb4c027333f786ffc6810e95188ec9f601d
MD5 52a0fa2db61f22b70a09628a67348a70
BLAKE2b-256 fc49b7ec0fbec75cf2046a456e85bffa38111a1efb5e6682d3180041bb1135c4

See more details on using hashes here.

Supported by

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