Statistics
| Branch: | Tag: | Revision:

root / README.i18n @ d7f0ad6e

History | View | Annotate | Download (1.7 kB)

1
DJANGO TRANSLATIONS OF STATIC TEXT
2

    
3
0)from our project's base, we add directory locale
4
$mkdir locale
5

    
6
then we add on the settings.py the language code
7
eg
8
LANGUAGES = (
9
  ('el', u'Ελληνικά'),
10
  ('en', 'English'),
11
)
12

    
13

    
14
1)for each language we want to add, we run makemessages, from our project's base:
15

    
16
$ django-admin.py makemessages -l el -e=html,txt,py
17

    
18
this will add the Greek language, and we specify that html, txt and python files contain translatable strings
19

    
20
2)we translate our strings. 
21
on .py files, (eg views.py), we add on the beggining of the file
22

    
23
from django.utils.translation import gettext_lazy as _
24

    
25
and then each string that needs translation becomes like this:  _('string')
26
eg
27

    
28
help_text=_("letters and numbers only"))
29
'title': _('Ubuntu 10.10 server 64bit'),
30

    
31

    
32
on django templates (html files), on the beggining of the file we add {% load i18n %} 
33
then on each string that needs to be translated, we put it on {% trans "string" %}, for example {% trans "Home" %}
34

    
35

    
36
3)when we have put our strings to be translated, from the project's base we run
37
$ django-admin.py makemessages -l el -e=html,txt,py
38
processing language el
39

    
40
this creates (or updates) the po file for the Greek language. We run this command each time we add new strings to be translated. After that, we can translate our strings, on the po file (locale/el/LC_MESSAGES/django.po)
41

    
42
4)when we are ready, we run the following command from the project's base
43
$ django-admin.py compilemessages
44

    
45
this compiles the po files to mo. 
46

    
47
Our strings will appear translated once we change the language (eg from a dropdown menu in the page)
48

    
49
More info:
50
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
51