Hooks for pre-commit useful working with PO files
BSD-3-CLAUSE License
Hooks for pre-commit useful working with PO files.
- repo: https://github.com/mondeja/pre-commit-po-hooks
rev: v1.7.3
hooks:
- id: obsolete-messages
- id: untranslated-messages
- id: fuzzy-messages
- id: remove-django-translators
- id: standard-metadata
- id: max-lines
args: ["10000"]
obsolete-messages
Checks for obsolete messages printing their line numbers if found.
untranslated-messages
Checks for untranslated messages printing their line numbers if found.
-m/--min
: Minimum number of messages that must be translated in each file%
at the end of the value.fuzzy-messages
Checks for fuzzy messages printing their line numbers if found.
lreplace-extracted-comments
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""
.-d/--dry-run
: Don't do the replacements, only writes to stderr the locationsremove-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.
-h/--header HEADER
: Header name to match in metadata. This argument can be-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-h/--header
must-n/--no-metadata
: When this option is passed, the hook instead checks that-r/--remove/--remove-metadata
: When this option is passed the metadata willstandard-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.
-r/--remove/--remove-metadata
: When this option is passed the metadata willremove-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"
max-lines
Define a maximum number of lines for each PO file. Pass an interger in the first argument:
- id: max-lines
args:
- "10000"
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%"