Statistics
| Branch: | Tag: | Revision:

root / README.i18n @ 52194743

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
$ ./bin/django-admin.py makemessages -l el -e html,txt,py
17
(./bin/django-admin.py makemessages -l el -e html,txt,py --ignore=lib/*)
18

    
19

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

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

    
25
from django.utils.translation import gettext_lazy as _
26

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

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

    
33

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

    
37

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

    
42
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)
43

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

    
47
this compiles the po files to mo. 
48

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

    
51
More info:
52
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
53