Translating Devilry

Easy mode — using the web-interface

Translating Devilry using the web-gui is very simple, all you need is to understand English, and the language you are translating Devilry into.

Finding the translation web-gui

The translation GUI is available at /i18n/translategui on any Devilry instance. So, for example if you have access to Devilry at http://devilry.ifi.uio.no, you can translate Devilry using http://devilry.ifi.uio.no/i18n/translategui.

Using the GUI

If you want to make an entirely new translation, click the New-button and start adding translations to the Translation-column. The original English text is in the Default-column.

Saving your changes

Save your changes using the Export-button. This will download the current translation to you machine.

Load a translation

If you want to change an existing translation, one you have saved, or one of the translations provided by Devilry, click the Load-button. Paste the contents of a file you have exported (see previous section), or choose Load from server.

Edit long lines

Double click on the default text to open a window that lets you edit long lines.

Add translations to Devilry

If you have translated Devilry using the GUI as explained in Easy mode — using the web-interface, you can send your translation file (devilry-translation.json), to your local Devilry administrator, and they can follow the instructions in the rest of this section.

How translations work

Devilry is a set of independent Django applications. Each application manage its own translations. Before translations can be used in production, we merge translations from all apps into a single file for each language/locale.

Decoupling translations from the GUI

When you receive a translation created as explained in Easy mode — using the web-interface, you have to decouple the translation and choose the language name using the devilry_i18n load command as so:

$ bin/django_production.py devilry_i18n load -v2 <language-code> /path/to/devilry-translation.json

Where <language-code> is a single word (lower-case english letters, numbers, underscore and dash). Remove -v2 make it non-verbose.

How do I avoid collisions with builtin translations?

Your translation files will be prefixed with local-. Translations with this prefix is never added to Devilry, and is therefore safe from future collisions with builtin devilry translations. Developers may check out --help to see how to get rid of the prefix.

Prepare translations for the web

Use the devilry_i18n export to merge all localizations into a single file for each language/locale:

$ bin/django_production.py devilry_i18n export -v2

This places the files in the appropriate place for static files. Next, you need to run collectstatic:

$ bin/django_production.py collectstatic

See the the install and update guides on the Wiki for more details about collectstatic.

Geek mode — Edit the translation files

Each application (in devilry/apps/) keeps their translations in static/APPNME/i18n/. Just copy messages.yaml into a file named messages_<langcode>.yaml where <langcode> is a unique identfier for your translation. For translations for local use (not intended to be distributed with Devilry), the <langcode> should be prefixed with local- (See: How do I avoid collisions with builtin translations?).

Example

A good example is the translations for the core app, which lives in devilry/apps/core/static/core/i18n/.

Localization middleware

class devilry.apps.i18n.middleware.LocaleMiddleware[source]

Bases: object

Locale middleware.

Detects the current locale in this order:

  1. If settings.DEBUG is True and ‘locale’ GET header, use the locale in the header.
  2. Use the ‘languagecode’ in the GET header if it is valid. If the user is authenticated, store the language code as their preferred language.
  3. If the user has a valid languagecode in their preferences, use it.
  4. Check the ACCEPT_LANGUAGE HTTP header.

2 makes it possible to use ?languagecode=LANGCODE to change the language preference. Valid language codes are those in DEVILRY_I18N_LANGCODEMAPPING.

Preferred language code is stored in the languagecode field on the user profile.

Uses devilry.apps.i18n.utils.get_languagecode().

Utils

devilry.apps.i18n.utils.get_languagecode(user, accept_language_header=None, languagecodemapping={'DEFAULT': ''}, default_languagecode='DEFAULT')[source]

Get the appropriate language code from the provided information:

  1. If the user has a valid languagecode in their preferences, use it.
  2. Check the ACCEPT_LANGUAGE HTTP header, and use it as long as parsing it yields a language code that is is languagecodemapping.
  3. Return the default_languagecode as the last fallback.

As long as default_languagecode is in languagecodemapping, this function is guaranteed to yield a language code that is present as a key in languagecodemapping.