Skip to main content

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

Project description

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 currently at a beta level. It works and has a test coverage above 90%. But it lacks documentation and real world tests.

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

Usage

As it is only a hatchling hook plugin, this package has no direct interface. It uses the logging package for its messages which are written to the standard output stream, so it is possible to increase its verbosity when the behaviour is unexpected.

.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 build 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"

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.

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_msgfmt_s_ball-0.2.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

hatch_msgfmt_s_ball-0.2.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file hatch_msgfmt_s_ball-0.2.1.tar.gz.

File metadata

  • Download URL: hatch_msgfmt_s_ball-0.2.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for hatch_msgfmt_s_ball-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fd980c65f2d402164a511b48b829ad01dab120b80cb012cf272e609266b4e3f6
MD5 a4f98f465466ec92dffbd671c41c9c2e
BLAKE2b-256 806a7b02fccc54cfdb58b97fc0dc8e5b46d8a08574aa1e20702953d0606d0425

See more details on using hashes here.

File details

Details for the file hatch_msgfmt_s_ball-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hatch_msgfmt_s_ball-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad658c252051111b67a694083d1b4cb08018a066585662e70ce83e5156f7de43
MD5 a63590e4046f48cb94cce0384bc5b53f
BLAKE2b-256 53fb9691214c4545675c4dc6b1b9ff7d8e443d8d607ce971286c424fbf4dca38

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