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.2.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

sanpo-0.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanpo-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.5.0

File hashes

Hashes for sanpo-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8a90ab5497af1033a530a9d99f1063ef12ebd467ddafa042bf083c815ada5116
MD5 0f5a808e0e61826eee2025d99dddfe43
BLAKE2b-256 93ba0c8cbd0e65884bdd7a6c06d620f6461ee172b50e43643b08241155378886

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanpo-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.5.0

File hashes

Hashes for sanpo-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15c84198fccdfd318cce9309cf98c942d18ea2a6cea1d1245f96b4c883b4567c
MD5 e2d317baaee92e09a7f70d3d60f0efe1
BLAKE2b-256 352c2c6c9fdee1336ea68d1246dbf4e5bd9644544b82ad404d23e2f82bd1c7f5

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