Skip to main content

Extra keywords for Django

© 2014-2015 Thomas Khyn

Tested with Django 1.4 to 1.8 and all supported versions of Python.

About

The django makemessage management command parses the code of an application to generate .pot and .po files, provided the strings to be translated are called by the gettext-like functions (gettext, ugettext, ngettext, ugettext_lazy, etc.) or the _ alias.

However, it is quite common to use other aliases than _, for example for lazy translation, where _l can be used.

Before version 1.7, Django does not provide a way to specify other aliases that may be used for translation strings. This plugin fills this gap, without having to patch the django code itself.

From version 1.7, it is possible to use the xgettext_options in a custom makemessages command. Using this app saves you the hassle of programming a custom command.

Installation

As straightforward as it can be, using pip:

pip install django-extra_keywords

Then you will need to add 'extra_keywords' to your INSTALLED_APPS. Note that it does not make any sense to have this application installed in production and that it may only used in a development settings module.

Usage

Once installed, you can:

  • either define GETTEXT_EXTRA_KEYWORDS in your settings module as a tuple or list containing the keywords you would like to add:

    GETTEXT_EXTRA_KEYWORDS = ('_l', '_n:1,2')
  • or use it from the command line, using the --extra-keyword option (with no s, to add several keywords you have to repeat the option):

    manage.py makemessages [...] --extra-keyword=_l [...]

Keyword format

When using aliases for one-argument functions (ugettext, ugettext_lazy …), simply use the alias as a keyword. When using aliases for several arguments functions, you need to specify them, according to the following table:

Function type

Keyword format

gettext*

X

ngettext*

X:1,2

pgettext*

X:1c,2

npgettext*

X:1c,2,3

Example: if _n is an alias for ungettext, the keyword to use in GETTEXT_EXTRA_KEYWORDS or the makemessages command is '_n:1,2'.

Metadata

Release files for django-extra_keywords 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-extra_keywords 1.1.2
File Size Uploaded Provenance Actions
django-extra_keywords-1.1.2.zip 11.3 kB Without provenance Details for django-extra_keywords-1.1.2.zip

Release files / django-extra_keywords-1.1.2.zip

Download URL django-extra_keywords-1.1.2.zip
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9ff99ee6118de1a79e20dba3c8f04f32dbbb5e13ac45d85b64051e5d557b316a
BLAKE2b-256 checksum
How to use checksums
e078aa87a2c1baa5355a65bab311ce609045e9c148bf82bd6421c296ea8f7029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-extra_keywords 1.1.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page