Statistics
| Branch: | Tag: | Revision:

root / README.i18n @ b216cb77

History | View | Annotate | Download (1.7 kB)

1 d7f0ad6e provetza
DJANGO TRANSLATIONS OF STATIC TEXT
2 d7f0ad6e provetza
3 d7f0ad6e provetza
0)from our project's base, we add directory locale
4 d7f0ad6e provetza
$mkdir locale
5 d7f0ad6e provetza
6 d7f0ad6e provetza
then we add on the settings.py the language code
7 d7f0ad6e provetza
eg
8 d7f0ad6e provetza
LANGUAGES = (
9 d7f0ad6e provetza
  ('el', u'Ελληνικά'),
10 d7f0ad6e provetza
  ('en', 'English'),
11 d7f0ad6e provetza
)
12 d7f0ad6e provetza
13 d7f0ad6e provetza
14 d7f0ad6e provetza
1)for each language we want to add, we run makemessages, from our project's base:
15 d7f0ad6e provetza
16 461a2ec9 Markos Gogoulos
$ ./bin/django-admin.py makemessages -l el -e html,txt,py
17 edda4d30 Markos Gogoulos
(./bin/django-admin.py makemessages -l el -e html,txt,py --ignore=lib/*)
18 edda4d30 Markos Gogoulos
19 d7f0ad6e provetza
20 d7f0ad6e provetza
this will add the Greek language, and we specify that html, txt and python files contain translatable strings
21 d7f0ad6e provetza
22 d7f0ad6e provetza
2)we translate our strings. 
23 d7f0ad6e provetza
on .py files, (eg views.py), we add on the beggining of the file
24 d7f0ad6e provetza
25 d7f0ad6e provetza
from django.utils.translation import gettext_lazy as _
26 d7f0ad6e provetza
27 d7f0ad6e provetza
and then each string that needs translation becomes like this:  _('string')
28 d7f0ad6e provetza
eg
29 d7f0ad6e provetza
30 d7f0ad6e provetza
help_text=_("letters and numbers only"))
31 d7f0ad6e provetza
'title': _('Ubuntu 10.10 server 64bit'),
32 d7f0ad6e provetza
33 d7f0ad6e provetza
34 d7f0ad6e provetza
on django templates (html files), on the beggining of the file we add {% load i18n %} 
35 d7f0ad6e provetza
then on each string that needs to be translated, we put it on {% trans "string" %}, for example {% trans "Home" %}
36 d7f0ad6e provetza
37 d7f0ad6e provetza
38 d7f0ad6e provetza
3)when we have put our strings to be translated, from the project's base we run
39 461a2ec9 Markos Gogoulos
$ django-admin.py makemessages -l el -e html,txt,py
40 d7f0ad6e provetza
processing language el
41 d7f0ad6e provetza
42 d7f0ad6e provetza
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 d7f0ad6e provetza
44 d7f0ad6e provetza
4)when we are ready, we run the following command from the project's base
45 461a2ec9 Markos Gogoulos
$ ./bin/django-admin.py compilemessages
46 d7f0ad6e provetza
47 d7f0ad6e provetza
this compiles the po files to mo. 
48 d7f0ad6e provetza
49 d7f0ad6e provetza
Our strings will appear translated once we change the language (eg from a dropdown menu in the page)
50 d7f0ad6e provetza
51 d7f0ad6e provetza
More info:
52 d7f0ad6e provetza
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/