Translation

Cantemo can be translated in to different languages and use different timezone and currency information.

Requirements

As a first step, verify that your Cantemo license does support/include the translation module.

Creating translations requires GNU gettext utilities to be installed to create the translatable files and to compile those files into usable translations. On a Linux system this can be installed by installing gettext:

yum install gettext

Having translations on the system has no extra requirements but there is a processing overhead for using internationalization.

Settings

The settings in portal.conf are:

LANGUAGE_CODE: en

This sets the base language that should be served if the other methods of resolving which language don’t come to any conclusion.

USE_I18N: True

Turns on and off Internationalization site wide.

Creating translation files for a new language

To create the translation files, they need to be generated from the code and HTML files. A management command has been created for doing this for Cantemo. To invoke and translate into Swedish:

./manage.py translateportal -l sv

This will take all phrases used by the application and put them into a .po file under the /opt/cantemo/portal/portal/locale/sv directory.

This command should be invoked from the directory that contains the “portal” and “portal_themes” directory. If you want to update all existing languages on the system you can type the following:

./manage.py translateportal --all

The translateportal command need only be run once for each new version of Cantemo you upgrade to. See below for instructions on how to adapt a translation for a newer version of Cantemo.

Now you shoud translate your files. Edit the languagefiles that you created with the commands above. For example /opt/cantemo/portal/portal/locale/sv/LC_MESSAGES/django.po So for example in those files you will see something like this:

msgid "City"
msgstr ""

Then you should add your translation as the msgstr like this:

msgid "City"
msgstr "Stad"

After the files have been translated, they should be compiled for use using the following commands (if you are using a development setup, please replace the path to django-admin.py with the appropriate location):

cd /opt/cantemo/portal/portal
sudo /opt/cantemo/python/bin/django-admin.py compilemessages

The above commands will compile your .po files to binary .mo files and they should now be ready for use.

Enabling the new translation

To enble your language you need to add it to /opt/cantemo/portal/portal/localsettings.py

Like this:

LANGUAGES = (
    ('en', 'English'),
    ('en-gb', 'British English'),
    ('sv', 'Swedish'),
)

Now you should be able to restart portal and see your translations.

Maintaining translation files

After you have upgraded to a new version of portal, you may have to adapt you translation as some strings may have been added, changed or removed. To do this, run the translateportal command as shown in the earlier section:

./manage.py translateportal -l sv

This will once again go through all the strings in the HTML pages and the code. The difference from above is that now your .po file will be updated with the strings from the new version. If a string has changed, it will be marked as fuzzy like below. This signals that this is a string which almost matched an earlier translation and that you should make sure the translation is still appropriate for the new original string.:

#: portal_themes/core/templates/users/vs_users_all.html:23
#, fuzzy
msgid "View Deactivated"
msgstr "Visa avaktiverade"

When you have made sure the translation is correct you should remove the line:

#, fuzzy

as the string otherwise will be ignored by compilemessages.

Any string which is present in your translation but which cannot be found in the source will be commented out using the notation #~ like the following:

#~ msgid "No jobs found"
#~ msgstr "Inga jobb kunde hittas"

Both strings marked as fuzzy and strings which have been commented will be ignored by the compilemessages command so you should go through your translation file and make sure it the translations are appropriate for the new version.

After the files have been fully adapted to the new version, they should be compiled for use using the following commands (if you are using a development setup, please replace the path to django-admin.py with the appropriate location):

cd /opt/cantemo/portal/portal
sudo /opt/cantemo/python/bin/django-admin.py compilemessages

The above commands will compile your .po files to binary .mo files and they should now be ready for use.

Creating translation files for Apps

Install the Apps that you want to translate on to the system. Make sure that they run as expected on the Portal system, then following the instructions above for creating translation files.

Creating Javascript translation files

Created Javascript translation files is very similar to that of creating normal translation files except that we have to supply the domain “djangojs”:

./manage.py translateportal -d djangojs -l sv

This will search all JS files that uses the gettext() javascript function. After you have translated the resulting djangojs.po file compile using:

cd /opt/cantemo/portal/portal
sudo /opt/cantemo/python/bin/django-admin.py compilemessages

The translations will be usable using gettext()

Viewing translations

The recommended method for using translations is to have the locale of the machine accessing Portal set to one of the translations. If no locale can be matched to a translation in Portal the LANGUAGE_CODE setting is used.