Adding new languages to Baruwa

September 29, 2011 at 08:06 AM | categories: Baruwa

UPDATE: A newer and simpler way to translate Baruwa is now available

Translating Baruwa to your own language is dead simple, in this post i will be running through the steps required to add a new language to Baruwa.

The Baruwa source code is maintained in a git repo at github, so some basic git knowledge is required. There are lots of good tutorials on how to use git so if you have not used git before i suggest you familiarize your self with git, the following resources should be able to get you up and running.

Okay with that out of the way lets get started with a sample translation to Danish.

At the time of writing, there was no danish translation in the git tree so thats why i have chosen to use danish.

Create a virtualenv

Translation of Baruwa requires a working Django installation as you are most likely to be working on your desktop machine, we use a virtual python environment so as not to pollute your python system directories.

To create a virtualenv you need to install the python virtualenv package.

Ubuntu/Debian:

apt-get install python-virtualenv

RHEL/Centos/SL/Fedora:

yum install python-virtualenv

Mac OSx:

port install py-virtualenv

You can now create the virtualenv:

virtualenv --no-site-packages --clear --distribute --prompt="Baruwa-translation " py-translation

A directory called py-translation is created, you now have to activate the virtualenv:

source py-translation/bin/activate

Your prompt will change to something like "Baruwa-translation <hostname>:python <username>"

Fork the baruwa git repo

You do that by going to https://github.com/akissa/baruwa and click fork, this creates your our git tree.

Clone your git tree

Now clone your tree such that you can start the translation:

git clone git@github.com:<your_username>/baruwa.git

Configure the main baruwa repo as one of your remotes to enable you to pull down changes from the trunk version:

cd baruwa
git remote add upstream git://github.com/akissa/baruwa.git
git fetch upstream

Create the new language

Create a development environment, the command will download and install all packages required to run Baruwa:

python setup.py develop

Now change to the source directory and create the Danish (da) language files:

cd src/baruwa
baruwa-admin makemessages -l da
baruwa-admin makemessages -d djangojs -l da

The following files will be created:

locale/da
locale/da/LC_MESSAGES
locale/da/LC_MESSAGES/django.po
locale/da/LC_MESSAGES/djangojs.po

The django.po is your python/template strings, and djangojs are the javascript strings. You can now open those files and add your translations.

Compile the new translations

The translations need to be compiled to .mo files for you to be able to use them:

baruwa-admin compilemessages

Testing

To test, set "da" as your language code in settings.py:

LANGUAGE_CODE = 'da'

Add the language to the list of languages users can select, edit settings.py and add a new the language to the existing languages:

LANGUAGES = (
  ('en', ugettext('English')),
  ('af', ugettext('Afrikaans')),
  ('it', ugettext('Italian')),
  ('cs', ugettext('Czech')),
  ('fr', ugettext('French')),
  ('pl', ugettext('Polish')),
  ('da', ugettext('Danish')),
)

The startup a dev server and browse to http://127.0.0.1:8000:

baruwa-admin runserver

You should see Baruwa with the Danish translations.

/imgs/baruwa-danish.png

Contributing the translations

When you have tested and are happy with what you see, commit the changes and push to your github repo, then send me a pull request on github:

git add .
git commit
git push