We use Weblate to manage PyPI translations across several languages. Visit the Warehouse project on Weblate to contribute.

If you are experiencing issues as a translator, please let us know by opening a translation issue on the Warehouse issue tracker.

Adding a newly completed translation

Weblate will automatically add commits to a pull request as translations are updated.

When a translation reaches 100%, it should be added as a known locale and have it’s MO file (Machine Object file) compiled.

To add a new known locale:

  1. Check for outstanding Weblate pull requests and merge them if so.
  2. In a new branch, add a key/value to the KNOWN_LOCALES mapping in warehouse/i18n/ The key is the locale code, and corresponds to a directory in warehouse/locale.
  3. Compile the MO file for the locale by running make build-mos. This may recompile some existing MO files as well, but should add a new MO file for the new locale.
  4. Commit these changes (including all *.mo files) and make a new pull request which adds them.

Marking new strings for translation

In an HTML template, use the {% trans %} and {% endtrans %} tags to mark a string for translation.

In Python, given a request context, call request._(message) to mark message for translation. Without a request context, you can do the following:

from warehouse.i18n import localize as _
message = _("Your message here.")

Passing non-translatable values to translated strings

To pass values you don’t want to be translated into translated strings, define them inside the {% trans %} tag. For example, to pass a non-translatable link request.route_path('classifiers') into a string, instead of placing it directly in the string like so:

{% trans trimmed %}
Filter by <a href="request.route_path('classifiers')">classifier</a>
{% endtrans %}

Instead, define it inside the {% trans %} tag:

{% trans trimmed href=request.route_path('classifiers') %}
Filter by <a href="{{ href }}">classifier</a>
{% endtrans %}

Marking new strings for pluralization

To pluralize a translated string in an HTML template, use the {% pluralize %} tag to separate the singular and plural variants of a string, for example:

{% trans trimmed n_hours=n_hours %}
This link will expire in {{ n_hours }} hour.
{% pluralize %}
This link will expire in {{ n_hours }} hours.
{% endtrans %}

This is not yet directly possible in Python for Warehouse.

Marking views as translatable

If a view’s renderer uses translations, you should mark the view as translatable by setting the has_translations option in the view’s configuration:

class SampleViews: