Skip to main content

hatch-msgfmt-s-ball

PyPI - Version PyPI - Python Version


Automatically compile po files to mo ones at build time using msgfmt.py

Table of Contents

Goal

This package is a hatchling plugin that helps to automatically compile translation sources at build time. It internally uses a patched version of the msgfmt.py script from the Tools folder of the CPython source. Because of that it has no dependency and does not require any external tools.

Current Status

This package is released as Production/Stable. It has a test coverage above 90%. I currently use it for (the development version of) another project of mine i18nparse

Releases use a semantic major.minor.patch versioning. The full source code is available on GitHub.

Old Python versions support

Python 3.8 has reached its end of life, but it is still shipped in WSL. For that reason, it is no longer supported starting with the 1.1.0 version, but it is still supported in the 1.0.0 one. Major improvements or bug fixes should be implemented in the 1.0 branch.

Usage

As it is only a hatchling hook plugin, this package has no direct interface. It uses the Application object provided by hatchling for its messages, so it is possible to increase its verbosity when the behaviour is unexpected by just passing -v params to the hatch build command.

.po files

The source .po are expected to be in a folder under the root source directory. The default directory is messages but it can be changed through the configuration file. It can even be . if the files are directly in the root directory.

They are expected to be named LANG.po or domain-LANG.po. When no domain is present in the file name, the default domain is the last component of the source folder, or the package name if the source folder is . or messages.

LANG folders organization

Alternatively the source directory can contain LANG folders (e.g. fr_CA or es) that in turn contain domain.po files, possibly under a hierarchy of subfolders. The goal is to mimic a classical locale hierarchy: LANG/LC_MESSAGES/domain.po

It is even possible (but not recommended) to mix both organizations.

.mo files

For every .po file found, a corresponding compiled file is generated as locale/LANG/LC_MESSAGES/domain.mo under the project root directory. The default locale name can be changed through the builder configuration.

Configuration

The hatch-msgfmt-s-ball plugin can be configured as any other plugin through the pyproject.toml file. You must first declare it with:

[build-system]
requires = ["hatchling", "hatch-msgfmt-s-ball"]
build-backend = "hatchling.build"

Then you have to tell the builder that it must be called for the wheel target:

[tool.hatch.build.targets.wheel.hooks.msgfmt]

That section can be left empty if you accept the defaults. It is equivalent to:

[tool.hatch.build.targets.wheel.hooks.msgfmt]
locale = "locale"
messages = "messages"

In addition to the locale and messages options to respectively declare the source folder containing the po files and the generated locale folder, it is possible to declare a default domain with the domain directive:

[tool.hatch.build.targets.wheel.hooks.msgfmt]
domain = "my_app"
messages = "src"

As the messages folder is not named messages the default domain would have been src without the domain directive.

Installation

For normal usage, no installation is required. Any Python installer using the pyproject.toml file will be able to automatically download and install it at build time.

Developer installation

If you want to use the source of hatch-msgfmt-s-ball, you can download a source package form PyPI, or better clone it from GitHub:

git clone https://github.com/s-ball/hatch-msgfmt-s-ball.git

You will benefit from git for you own changes.

Contributing

As I am the only developer, I cannot guarantee very fast feedbacks. Anyway, I shall be glad to receive issues or pull requests on GitHUB.

License

hatch-msgfmt-s-ball is distributed under the terms of the MIT license.

Metadata

Release files for hatch-msgfmt-s-ball 1.1.2

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-msgfmt-s-ball 1.1.2
File Size Uploaded Provenance Actions
hatch_msgfmt_s_ball-1.1.2.tar.gz 17.7 kB Without provenance Details for hatch_msgfmt_s_ball-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hatch-msgfmt-s-ball 1.1.2
File Interpreter ABI Platform Actions
hatch_msgfmt_s_ball-1.1.2-py3-none-any.whl Python 3 none any Details for hatch_msgfmt_s_ball-1.1.2-py3-none-any.whl

Total release size: 33.1 kB

Release files / hatch_msgfmt_s_ball-1.1.2.tar.gz

Download URL hatch_msgfmt_s_ball-1.1.2.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
416f6a4f4fee15770f849adf300dc4d28b1512f9662a242b4230754f6800d40e
BLAKE2b-256 checksum
How to use checksums
b52014cd38fae72932474c4a611560c41587b2d0f9e1204009ed92aa378a30fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / hatch_msgfmt_s_ball-1.1.2-py3-none-any.whl

Download URL hatch_msgfmt_s_ball-1.1.2-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16739be44ccaf5d3e1651f50af57a06fb8762f8821fce57dad06bf21b29cace7
BLAKE2b-256 checksum
How to use checksums
5ae1dee80ddd1478af84f9b710d655df2b2d9c60d23eef3ac53c90ed5137b8e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for hatch-msgfmt-s-ball 1.1.2

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