Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Translation

evgenyfadeev edited this page · 22 revisions

Currently cnprog “understands” Chinese, English and Spanish.

To translate 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
<p>This is my text</p>

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

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

Translation gotcha’s

  • do not change msgid lines unless you are ready to change those strings in all language .po files and source template and .py files
  • try to limit your edits to msgstr lines – they contain actual translations
  • remember that ampersand – & symbol in html output will make documents invalid unless it’s part of html entity. So for ampersand symbol itself use &amp; sequence.
  • when translation strings contain html markup it’s better to validate the views using those strings with the w3c html validator
Something went wrong with that request. Please try again.