Skip to main content

Django app for translating Django .po files. It uses deep-translator and polib

Installation

when using pip:

pip install django-translatemessages

When using poetry:

poetry add django-translatemessages

Configuration

You must declare in your settings.py what translator to use and its params. Please refer to deep-translator Translators to know what parameters to specify (Note that django-translatemessages automatically add source and target parameters)

To configure GoogleTranslator, add in your settings.py:

TRANSLATEMESSAGES_PARAMS = {
    "translator": {
        "class": "GoogleTranslator",
        "params": {},
    },
}

To configure DeeplTranslator, you will need an API key, add in your settings.py:

TRANSLATEMESSAGES_PARAMS = {
    "translator": {
        "class": "DeeplTranslator",
        "params": {
            "api_key": "your deepl api key",
        },
    },
}

A good pratice in a Django application is to encapsulate strings to be translated into square brakets, thus, you will noticed at once what strings has not been translated yet. You can ask django-translatemessages to extract the string to translate from the source string. Use a regex which selects with parentheses the text to extract. Note that if there is no match, the translation will not occur.

For example if you want to translate [my english string] into my french string with deepl, put in settings.py:

TRANSLATEMESSAGES_PARAMS = {
    "extract_regex": r"\[(.*)\]",
    "translator": {
        "class": "DeeplTranslator",
        "params": {
            "api_key": "your deepl api key",
        },
    },
}

The source language is en by default, but you can use another one in your settings.py:

TRANSLATEMESSAGES_PARAMS = {
    "source_lang": "fr",
    ...
}

IMPORTANT : By default, django-translatemessages will produce translations with the flag fuzzy. This force the developer to validate manually each translation.

To do so, edit each django.po file, search for the line #, fuzzy and remove it if you agree with the proposed translation. If you do not do this, Django will not display the translation. You can also use poedit and press CTRL + RETURN on each highlighted translation you agree.

To disable auto-fuzzy feature, use this in your settings.py:

TRANSLATEMESSAGES_PARAMS = {
    "auto_fuzzy": False,
    ...
}

Usage

To auto-translate all languages in all apps:

python ./manage.py translatemessages

Do not forget to do a makemessages before if needed (See Django documentation)

For more options, run python ./manage.py translatemessages -h

News

0.0.6 (2025-02-04)

  • Ignore translator API error in order to write .po file with already translated strings

0.0.5 (2023-06-29)

  • Force translation of fuzzy strings except when obsolete or already translated by django-translatemessages

0.0.4 (2023-06-21)

  • Do not translate fuzzy strings

0.0.2 (2023-06-11)

  • First commit

Metadata

Release files for django-translatemessages 0.0.6

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-translatemessages 0.0.6
File Size Uploaded Provenance Actions
django-translatemessages-0.0.6.tar.gz 7.7 kB Without provenance Details for django-translatemessages-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-translatemessages 0.0.6
File Interpreter ABI Platform Actions
django_translatemessages-0.0.6-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_translatemessages-0.0.6-py2.py3-none-any.whl

Total release size: 15.3 kB

Release files / django-translatemessages-0.0.6.tar.gz

Download URL django-translatemessages-0.0.6.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
554c89941de8ac883c5e9588f046d971a3c1b71bfa90bff0b25a989925e81ee5
BLAKE2b-256 checksum
How to use checksums
6c476fe1b6808f48463ec8dcaaf2c3d327142249139c4d867c3eb13ff2edf303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / django_translatemessages-0.0.6-py2.py3-none-any.whl

Download URL django_translatemessages-0.0.6-py2.py3-none-any.whl
Size 7.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dfa7b1e2ae2a0bcfe0d1543d898d79bc913e29b96a4fe6bbb2109e9560185929
BLAKE2b-256 checksum
How to use checksums
7cbc2f871b394eaa4b25e56ca23165bbd1d3ff724106d035f51d7d47ba602bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for django-translatemessages 0.0.6

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