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