Skip to content

Adding a Locale to Phaidra (i18n)

mlent edited this page Oct 20, 2014 · 8 revisions

Steps for adding a locale to Phaidra

  1. Interface localization (HTML and Javascript Templates, Javascript)
  2. Content localization (Admin)
  3. Adding a translated (and aligned) work

Steps for adding a locale to Phaidra

1. Interface localization

Prologue: Include the language

Open up phaidra/settings.py. In the section LANGUAGES, add the language:

LANGUAGES = (
   ('en', 'English'),
   ('fa', 'Farsi'),
   ('de', 'German'),
   ('it', 'Italian'),
   ('hr', 'Croatian')
)

Prelude: django-admin.py makemessages

If you are updating translations, you will need to run the following command so that django finds and appends the new strings to django.po and djangojs.po.

Make sure your virtual environment is activated:

$ source env/bin/activate

And run these commands from the project root (/opt/phaidra). Replace argument of --locale=de with the locale (e.g. fa for Farsi).

$ django-admin.py makemessages --locale=de --extension=html --ignore=env --ignore=*.py
$ django-admin.py makemessages -d djangojs --locale=de --ignore=env --ignore=static/admin/*"

(Developer note: --ignore=static/admin/* currently does not actually ignore the admin files, owing to a bug in Django. See relevant pull request).

HTML and Javascript Templates

Open /opt/phaidra/locale/*/LC_MESSAGES/django.po, where * is the locale code you are interested in. You will find sets of strings which look something like this:

# templates/something.html:123
msgid "Words in English"
msgstr "Worte auf Deutsch"

The msgid is always the original in the file, and the msgstr is your translation. Simply go through this document and translate the English into your target language.

Javascript

You repeat the same action as before, but instead edit djangojs.po.

Compilemessages

Once you've translated the strings in django.po and djangojs.po, you need to compile them.

$ django-admin.py compilemessages

This will compile the messages for all languages.

2. Textbook Localization

Log in to the Phaidra Admin. You will need to create items within the following App categories:

  • Languages
  • Content

Simply assign the language you're working on to the Content you create, and it will show up on the interface when the language is selected.

3. Adding a translated (and aligned) work

4. Propagate your database changes to Github

In order to propagate the changes you've made within the admin panel to github, so others can load in your content as well, run the following command.

./manage.py dumpdata --natural --indent=4 --exclude=contenttypes --exclude=auth --exclude=tastypie > app/fixtures/db.json

You can then git add this file, along with any other localization-related files (e.g. *.mo, *.po), commit them, and push.


Additional steps for adding a source language to Phaidra

Developer Guide

Backend

Frontend

Content Guide

What did you break?

  • Postgres Database
  • Neo4j
  • Django
  • "The server"
  • Git
  • UI
Clone this wiki locally