Skip to main content

Simple script to manage multiple language catalogs in a django project.

Project description


Current version: 0.5

This script automates the creation and maintenance of multiple language catalogs across a django project. The current language maintenance tool included in django does not manage multiple catalogs sparsed through the django project tree, this script ends that. Using this script with transifex-client is a very good option.

How to install

To install this script you must copy it inside your project root (in the same directory as or you can make a “scripts” directory inside your project root and copy the script there.

Configuring django to use the script

Django has (in my opinion) the bad habit of including all the applications in the same variable: INSTALLED_APPS, that is not a good thing, because it doesn’t isolate the user applications.

What you need to do is just that, isolate your applications from the django ones, making another variable, for example MYPROJECT_APPS and then unite them to the django ones in INSTALLED_APPS. In this example case, the project applications have been separated into three categories: DJANGO_APPS, THIRDPARTY_APPS (applications included in the project but not developed by the team) and MYPROJECT_APPS, including just the project application that we have developed.

    # This list is from the builtin applications in django. Watch out for
    # applications that need some specific order, like django-grappelli in
    # this case. It's a third part app, but due to the load order, we must
    # put it here.

    # This list is from the third party software included in the project or
    # system-wide dependencies.

    # Modules created for the project and installed by default. You can add
    # here your own modules.


After you have configured your applications variables, you must declare the languages you will use on the project with LANGUAGES. If you already have a multilingual django project it’s quite probable that you already have this defined. If not, you will have to define a python dictionary with LANG_CODE:LANG_NAME. For example:

    ('es_ES', 'Espanol'),
    ('en_GB', 'English'),
    ('gl_ES', 'Galego'),

How to use the script

This script is run from the command line, in the project root or in the scripts directory. If you don’t exceute it from there it will fail to locate the file. It has three basic commands:

  • make Creates (or updates) all the language catalogs in your project

  • compile Compiles after translation all the language catalogs

  • clean Removes all the language catalogs from the project. Asks for confirmation first

There is also a “help” command which output is:

$ ./ --help
usage: [-h] {make,compile,clean} ...

e-cidadania language catalog generator. This script manages all the .po and
.mo files from templates, python code and javascript i18n (if used).

positional arguments:
    make                Create all the language catalogs for translation,
                        including JavaScript.
    compile             Compile all the language catalogs for use.
    clean               Delete all the language catalogs. After this you will
                        have to rebuild the catalogs and translate them.

optional arguments:
-h, --help            show this help message and exit

For example, to create or update your language catalogs, the command would be:

$ python make

Which output should be (we’re using e-cidadania project as example):

>> Languages to generate:
 - Espanol
 - English
 - Galego

>> Installed applications:
 - accounts
 - proposals
 - news
 - debate
 - spaces
 - staticpages
 - cal

>> Generating language catalog: accounts
processing language es_ES
processing language en_GB
processing language gl_ES

>> Generating language catalog: proposals
processing language es_ES
processing language en_GB
processing language gl_ES

(after ending the standard catalogs it starts with JavaScript ones)

>> Generating JavaScript language catalog: accounts
processing language es_ES
processing language en_GB
processing language gl_ES

>> Generating JavaScript language catalog: proposals
processing language es_ES
processing language en_GB
processing language gl_ES

(etc., etc.)

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-modular-languages-0.5.tar.gz (4.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page