Simple script to manage multiple language catalogs in a django project.
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 settings.py) 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.
DJANGO_APPS = ( # 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. 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.messages', 'grappelli.dashboard', 'grappelli', 'django.contrib.admin', 'django.contrib.comments', ) THIRDPARTY_APPS = ( # This list is from the third party software included in the project or # system-wide dependencies. 'django_wysiwyg', 'myproject.apps.userprofile', 'myproject.apps.tagging', #'django_extensions', ) MYPROJECT_MODULES = ( # Modules created for the project and installed by default. You can add # here your own modules. 'myproject.apps.accounts', 'myproject.apps.proposals', 'myproject.apps.news', 'myproject.apps.debate', 'myproject.apps.spaces', 'myproject.apps.staticpages', 'myproject.apps.cal', ) INSTALLED_APPS = DJANGO_APPS + THIRDPARTY_APPS + MYPROJECT_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:
LANGUAGES = ( ('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 settings.py 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:
For example, to create or update your language catalogs, the command would be:
$ python generate_languages.py make
Which output should be (we’re using e-cidadania project as example):