Skip to main content

Hatch build hook plugin for GNU gettext

Project description

Hatch Gettext

Package PyPI - Python Version PyPI - Version
Meta Hatch project Ruff GitButler Checked with mypy 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"

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.

Related Hatch plugin

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.

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

hatch_gettext-1.1.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

hatch_gettext-1.1.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file hatch_gettext-1.1.0.tar.gz.

File metadata

  • Download URL: hatch_gettext-1.1.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for hatch_gettext-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d08e4ab9f612ace00ed034fad92101c91637ea2c26f9f9926b9cb070c9295017
MD5 e2ad35559f9763027c6ff78212da54ed
BLAKE2b-256 cdb24d4832953d048af2c6cf6e56c5dc50cd2b661848c05346d7c13702ead6fa

See more details on using hashes here.

File details

Details for the file hatch_gettext-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hatch_gettext-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3356492a7f90a57a8ea1e0c4702ac62da3fd5f8e5e92790b5274d01e5f2420c6
MD5 c6c4d40ecddfd908fe6ddc78b3936ffe
BLAKE2b-256 3853c6f3c7fcc2dc8aa93323ea546ae1e701301bdef5c93719e43ea953cfe4eb

See more details on using hashes here.

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