Skip to main content

Sanitize PO files from gettext for version control

Project description

PyPI Python Versions Build Status Test Coverage Black License

sanpo

sanpo is a command line tool to sanitize PO files from gettext for version control.

The problem

The gettext tool collects text to be translated from source code in PO files that can be sent to translators. These files contain metadata about the project that can be helpful when using an email based workflow.

When creating a PO file the first time, these metadata look like this:

"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-06 16:16+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

However, when having the PO file under version control, these metadata get in the way. Most of them are available from the commit history. And when running gettext automatically as part of the build process, the PO-Revision-Date gets updated every time even if none of the messages changed, resulting in spuriously modified PO files without any actual changes worth committing.

The solution

Because your localized software does not use the PO files directly but the MO files compiled from them, the unhelpful metadata can be removed. Which is exactly what sanpo does.

A typical build chain would look like this:

  1. gettext - collect PO file
  2. msgfmt - compile into MO file
  3. sanpo - remove unhelpful metadata from PO
  4. commit possible changes in PO file

sanpo simple takes one or more PO files as argument, for example:

sanpo locale/de/LC_MESSAGES/django.po locale/en/LC_MESSAGES/django.po locale/hu/LC_MESSAGES/django.po

After this, the remaining metadata are:

"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

Using the special pattern ** folders can be scanned recursively.

To sanitize PO files for all languages in a certain folder, use for example:

sanpo locale/**/django.po

Django

For Django projects, the typical workflow is:

  1. django-admin makemessages
  2. django-admin compilemessages
  3. sanpo
  4. commit possible changes in PO file

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

sanpo-0.3.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

sanpo-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file sanpo-0.3.0.tar.gz.

File metadata

  • Download URL: sanpo-0.3.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sanpo-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bfcf84949c2c818c4da751b5e5c8d2ee540805dd393f8310d26b9fcb6c6eb38f
MD5 657b4cd713762971f91b18da0d131bb9
BLAKE2b-256 dc67a2b7031587ad379c42faf213035928711df46809207507b3b6fed28d6541

See more details on using hashes here.

File details

Details for the file sanpo-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sanpo-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sanpo-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8579054b4dfa253797725287f1aaf22ba88918a4f034c84264e19ced025902f2
MD5 f27867669e0b31e7cbca71018b0a4ce4
BLAKE2b-256 2405c5d869e356819f695b2822a5706d4bacd6e9dd71bdb9a7cc2dba5e54fad4

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