Skip to main content

Hatch Gettext

Package PyPI - Python Version PyPI - Version
Meta Hatch project Ruff GitButler pyrefly License: GPL v3 GitHub Sponsors

This provides a build hook plugin for Hatch that compiles multi-lingual messages with GNU gettext's tools msgfmt. It can also (optionally) use intltool to:

  • translate .xml and .desktop files
  • search for left out files
  • regenerate the .pot template
  • display a status report for all translations

Table of Contents

Configuration

The build hook plugin name is gettext.

Calling the plugin

Modify pyproject.toml to include the plugin as a build dependency:

[build-system]
requires = ["hatchling", "hatch-gettext"]
build-backend = "hatchling.build"

Skipping Platforms

This plugin may make less sense some platforms, e.g. Windows. To skip running this plugin on specific platforms use values from sys.platform in the configuration option skip-platforms, e.g.:

[tool.hatch.build.hooks.argparse-manpage]
skip-platforms = ["win32", "cygwin"]

Compiling messages with msgfmt

This plugin requires .mo files be created; it also requires that the directory storing them is within the project's base directory, and is not equal to the project's base directory or the directory in which po files are sourced. The mo file directory is set using locale-directory, which is required.

For example, for a project named myproject, and a src layout src/myproject, an acceptable directory in which to store the LC_MESSAGES/myproject.mo files would be src/myproject/locale

[tool.hatch.build.hooks.gettext]
locale-directory = "src/myproject/locale"

Optionally, specify values for the gexttext output name and the source directory where po files are found:

[tool.hatch.build.hooks.gettext]
locale-directory = "src/myproject/locale"
i18n-name = "myproject" 
po-directory = "po-files"

If i18n-name is not specified, the name in [project] in the pyproject.toml is used. If po-directory is not specified, the directory po is used.

Identifying left out files using intltool-update

With every source distribution (sdist) build, to search for left out files, which should have been listed in POTFILES.in or POTFILES.skip, set identify-left-out to true (the default value is false):

[tool.hatch.build.hooks.gettext]
locale-directory = "src/myproject/locale"
identify-left-out = true

Regenerating the .pot template using intltool-update

To regenerate the .pot template with every sdist build, set regenerate-template to true (the default value is false):

[tool.hatch.build.hooks.gettext]
locale-directory = "src/myproject/locale"
regenerate-template = true

Displaying a status report using intltool-update

To display a status report for all translations, set show-report to true (the default value is false):

[tool.hatch.build.hooks.gettext]
locale-directory = "src/myproject/locale"
show-report = true

Translating files using intltool-merge

This plugin allows for but does not mandate translating .xml and .desktop files using intltool-merge. Using [tool.hatch.build.hooks.gettext.files], specify the destination directories for the translated files using keys, and arrays of source files as values. For example:

[tool.hatch.build.hooks.gettext.files]
"share/applications" = ["data/net.myproject.desktop.in"]
"share/solid/actions" = ["data/kde/net.myproject.desktop.in"]
"share/metainfo" = ["data/net.myproject.metainfo.xml.in"]

Cleaning output files

The plugin includes logic to remove the files it outputs using hatch's clean hook. As well as individual files, any output directories created will also be removed, as long as these directories do not contain files created by something other than this plugin.

Running tests

To run the full test suite for all supported Python versions, run:

hatch test -a

To automatically generate a manual page from an ArgumentParser object, see hatch-argparse-manpage.

License

hatch-gettext is distributed under the terms of the GPL-3.0-or-later license.

Metadata

Release files for hatch-gettext 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hatch-gettext 1.1.4
File Size Uploaded Provenance Actions
hatch_gettext-1.1.4.tar.gz 32.3 kB Without provenance Details for hatch_gettext-1.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hatch-gettext 1.1.4
File Interpreter ABI Platform Actions
hatch_gettext-1.1.4-py3-none-any.whl Python 3 none any Details for hatch_gettext-1.1.4-py3-none-any.whl

Total release size: 53.5 kB

Release files / hatch_gettext-1.1.4.tar.gz

Download URL hatch_gettext-1.1.4.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
eb30b881bc9b2f042f7aa457cfc200073862a2b34760fd608434250ac4ca48ff
BLAKE2b-256 checksum
How to use checksums
7259e644eac17448d6c9fccefbef393a04993b61785f454e8b50ef069d699c67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":null,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.5.5 27 Jan 2026","python":"3.14.4","system":{"name":"Linux","release":"6.6.114.1-microsoft-standard-WSL2"}} HTTPX2/2.16.2

Release files / hatch_gettext-1.1.4-py3-none-any.whl

Download URL hatch_gettext-1.1.4-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cab13f3c3b3031222d468a2c4fce501dffc260683220589c0c32739f6d7e77f2
BLAKE2b-256 checksum
How to use checksums
8d27f4c43f4babb8fc11e7adee3b9d29ebff1fe2eb76c9957e4b54e679b3ce6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":null,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.14.4"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.5.5 27 Jan 2026","python":"3.14.4","system":{"name":"Linux","release":"6.6.114.1-microsoft-standard-WSL2"}} HTTPX2/2.16.2

Security for hatch-gettext 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page