Simple script to manage multiple language catalogs in a django project.
Project description
django-modular-languages
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:
$ ./generate_languages.py --help usage: generate_languages.py [-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,compile,clean} 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 generate_languages.py 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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-modular-languages-0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3251ae7af713358ddd8240026771f8174a5b81072dce1c4582d01d21d9a0e3c2 |
|
MD5 | 42c8dd16d82121ad696c68de7b5d649f |
|
BLAKE2b-256 | dd7cab32953f154a9d46e00904070c97350fef5849b64ff2bd413a5f7331ebde |