Registry / serialization / python-gettext

python-gettext

JSON →
library5.0pypypiunverified

python-gettext is a Python library and command-line tool designed to compile Gettext `.po` (Portable Object) files into `.mo` (Machine Object) files. These `.mo` files are then used by internationalization (i18n) systems for runtime message translation. The current version is 5.0, with releases typically tied to Python version compatibility or API refinements.

pip install python-gettext
INSTALL
IMPORT
SIG · PYTHON-GETTEXT
P
python-gettext
serializationpythonv5.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile_mo_file
from pythongettext import compile_mo_file
from pythongettext import compile_mo_file

This quickstart demonstrates how to programmatically compile a `.po` file into a `.mo` file using `gettext_compiler.compile_mo_file`. It creates a simple dummy `.po` file, compiles it, and then cleans up the generated files.

import os from gettext_compiler import compile_mo_file # Create a dummy .po file for demonstration po_content = ''' msgid "" msgstr "" "Project-Id-Version: Test Project\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" msgid "Hello, world!" msgstr "Hola, mundo!" ''' po_file_path = "example.po" mo_file_path = "example.mo" with open(po_file_path, "w", encoding="utf-8") as f: f.write(po_content) # Compile the .po file to a .mo file try: compile_mo_file(po_file_path, mo_file_path) print(f"Successfully compiled '{po_file_path}' to '{mo_file_path}'") except Exception as e: print(f"Error compiling file: {e}") finally: # Clean up the created files if os.path.exists(po_file_path): os.remove(po_file_path) if os.path.exists(mo_file_path): os.remove(mo_file_path)
python-gettext --version
Debug
Known issues
breakingThe primary import module name changed from `msgfmt_compiler` to `gettext_compiler` in version 5.0.
fix
Update your import statements from `from msgfmt_compiler import ...` to `from gettext_compiler import ...`.
affects: >=5.0
breakingPython 2 support was dropped in version 4.0. The library now requires Python 3.7 or newer.
fix
Ensure your project is running on Python 3.7+ to use `python-gettext` versions 4.0 and higher.
affects: >=4.0
gotchaThis library (`python-gettext`) is for *compiling* `.po` files to `.mo` files. It is often confused with Python's built-in `gettext` module, which provides runtime translation APIs using already compiled `.mo` files.
fix
Remember that `python-gettext` provides the `gettext_compiler` module for the build-time step of creating `.mo` files, while the standard `gettext` module is used at runtime for actual message lookup.
affects: All
gotchaIncorrect encoding of `.po` files can lead to compilation errors or corrupted `.mo` files. The compiler defaults to UTF-8.
fix
Ensure your `.po` files are consistently encoded, preferably UTF-8. If using a different encoding, you may need to pre-process the `.po` content before passing it to the compiler.
affects: All
Upgrade
Version history
5.0latest on PyPI · released Mar 30, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Resources
python-gettext — pip install python-gettext · libregistry