Skip to content
evgenyfadeev edited this page Sep 13, 2010 · 22 revisions

Currently cnprog “understands” Chinese, English and Spanish.

To translation to another language – you need to work on two files:

  • /locale/lang_code/LC_MESSAGES/django.po
  • /templates/content/js/com.cnprog.i18n.js

Steps to translate django.po file

  • create a directory /locale/your_lang_code/LC_MESSAGE
  • copy a django.po file from the translation that you understand to that new directory
  • translate strings that start with “msgstr”, keep strings “msgid” intact and preserve overall format.
  • any strings that have a comment above them like #, fuzzy will not be shown as translated – verify translation for those and then remorve the “fuzzy” string.
  • if a string takes variables – make sure to follow format of translation strings it should have things like %(the_variable)s to properly insert values
  • also strings like that must have a comment just above msgstr
    #, python-format
  • at any time run
    python manage.py compilemessages
    – that will create django.mo file that is actually feeding translations into the application

How does Django code connect with your translation

First thing in the template that uses translation you must include a line somewhere close to the top:

{% load i18n %}

Now you are ready to add translatable strings.

Instead of just typing strings like

This is my text

You will be enclosing text into translation tags – either {% trans "text" %} or
{% blocktrans %}some text{% endblocktrans %}

There are four use cases:

  • simple one-to-one one-liner string mapping – uses format {%trans "some text" %}
  • simple multiline string mapping
  • mapping with a variable substitution
  • mapping with variable substitution and pluralization

Clone this wiki locally