locale-simple
A tiny, sharp wrapper around gettext with sprintf-style formatting and
short, friendly helpers (l, ln, lp, ld, …). UTF‑8 only, by design.
The same API ships in three runtimes — Perl, Python and JavaScript — so
one set of .po files feeds your whole stack. Translate once, use
everywhere.
Why locale-simple?
- Same API across languages. A function called
lnpin Python behaves identically in Perl and JavaScript. No mental context switch when jumping between server, CLI tool and frontend. - One
.pofile for everything. Scrape strings from Perl/Python/JS sources with the same scraper, ship one translation bundle. sprintfbaked in. Both classic (%s) and positional (%1$s) placeholders — exactly like Perl'ssprintfand gettext'sxgettextformat strings expect.- Boring and small. Single-file module, no surprises, no magic.
Install
pip install locale-simple
Quick start
from locale_simple import l, ln, lp, ld, l_dir, l_lang, ltd
l_dir('data/locale') # where your .mo files live
ltd('myapp') # default text domain
l_lang('de_DE') # primary language
print(l("Hello"))
# → Hallo
print(ln("You have %d message", "You have %d messages", 1))
# → Du hast 1 Nachricht
print(ln("You have %d message", "You have %d messages", 5))
# → Du hast 5 Nachrichten
print(lp("button", "Open")) # context-disambiguated
print(ld("emails", "Welcome, %s", name)) # explicit domain
API at a glance
| Function | gettext equivalent | What it does |
|---|---|---|
l(msgid, *args) |
gettext |
Translate, then sprintf |
ln(msgid, msgid_plural, n, *args) |
ngettext |
Plural form for n |
lp(ctxt, msgid, *args) |
pgettext |
With disambiguating context |
lnp(ctxt, msgid, msgid_plural, n, *args) |
npgettext |
Plural + context |
ld(domain, msgid, *args) |
dgettext |
Specific text domain |
ldn(domain, msgid, msgid_plural, n, *args) |
dngettext |
Domain + plural |
ldp(domain, ctxt, msgid, *args) |
dpgettext |
Domain + context |
ldnp(domain, ctxt, msgid, msgid_plural, n, *args) |
dnpgettext |
The full thing |
Configuration helpers
| Call | Purpose |
|---|---|
l_dir(path) |
Locale directory containing <lang>/LC_MESSAGES/<domain>.mo |
l_lang(code) |
Set primary language (de_DE, pt_BR, …) |
ltd(domain) |
Default text domain |
l_dry(path) |
Append every encountered string to a .po-ish file (scrape mode) |
l_nolocales(bool) |
Skip lookup, return the formatted msgid (handy in tests) |
Sibling packages
| Runtime | Package | Repo path |
|---|---|---|
| Perl | Locale::Simple on CPAN |
lib/Locale/Simple.pm |
| Python | locale-simple on PyPI |
python/locale_simple.py |
| JavaScript | locale-simple on npm |
js/src/index.js |
All three share the same source tree: https://github.com/Getty/locale-simple
License
MIT © Torsten Raudssus
Metadata
Release files for locale-simple 0.109
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| locale_simple-0.109.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| locale_simple-0.109-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / locale_simple-0.109.tar.gz
| Download URL | locale_simple-0.109.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6753283870a5949eacbb4bd80fa6109cc3525de20cbb6ad7b4c28f9017a76ed5
|
|
BLAKE2b-256 checksum How to use checksums |
a68255603e67fba36d24687a8a103e951e4e668128c48e8b4989bdacca62f1c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.2
|
Release files / locale_simple-0.109-py3-none-any.whl
| Download URL | locale_simple-0.109-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8642bca527af5c430b214d2f19c1bb92e57c0830a06f13bfb3a36b47b49e7ea2
|
|
BLAKE2b-256 checksum How to use checksums |
dfbde8612fe3f67788488c3cbbbe7da35c41f1b6300ae5d885884716156b5e4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.2
|
Security for locale-simple 0.109
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.