Revision 271baf11 README.i18n
b/README.i18n | ||
---|---|---|
1 | 1 |
DJANGO TRANSLATIONS OF STATIC TEXT |
2 | 2 |
|
3 |
0)from our project's base, we add directory locale |
|
4 |
$mkdir locale |
|
3 |
0) From our project's base, we add directory locale |
|
5 | 4 |
|
6 |
then we add on the settings.py the language code |
|
7 |
eg |
|
8 |
LANGUAGES = ( |
|
9 |
('el', u'Ελληνικά'), |
|
10 |
('en', 'English'), |
|
11 |
) |
|
5 |
$mkdir locale |
|
12 | 6 |
|
7 |
then we add on the settings.py the language code e.g., |
|
13 | 8 |
|
14 |
1)for each language we want to add, we run makemessages, from our project's base: |
|
9 |
LANGUAGES = ( |
|
10 |
('el', u'Ελληνικά'), |
|
11 |
('en', 'English'), |
|
12 |
) |
|
15 | 13 |
|
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/*)
|
|
14 |
1) For each language we want to add, we run makemessages, from our project's
|
|
15 |
base:
|
|
18 | 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 | 19 |
|
20 |
this will add the Greek language, and we specify that html, txt and python files contain translatable strings |
|
20 |
This will add the Greek language, and we specify that html, txt and python |
|
21 |
files contain translatable strings |
|
21 | 22 |
|
22 |
2)we translate our strings. |
|
23 |
on .py files, (eg views.py), we add on the beggining of the file |
|
23 |
2) We translate our strings. |
|
24 | 24 |
|
25 |
from django.utils.translation import gettext_lazy as _ |
|
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.. |
|
26 | 29 |
|
27 |
and then each string that needs translation becomes like this: _('string')
|
|
28 |
eg
|
|
30 |
help_text=_("letters and numbers only"))
|
|
31 |
'title': _('Ubuntu 10.10 server 64bit'),
|
|
29 | 32 |
|
30 |
help_text=_("letters and numbers only")) |
|
31 |
'title': _('Ubuntu 10.10 server 64bit'), |
|
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" %} |
|
32 | 36 |
|
37 |
3) When we have put our strings to be translated, from the project's base we run |
|
33 | 38 |
|
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" %} |
|
39 |
$ django-admin.py makemessages -l el -e html,txt,py |
|
36 | 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) |
|
37 | 45 |
|
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
|
|
46 |
4) When we are ready, we run the following command from the project's base
|
|
47 |
|
|
48 |
$ ./bin/django-admin.py compilemessages
|
|
41 | 49 |
|
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 |
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) |
|
50 | 52 |
|
51 | 53 |
More info: |
52 | 54 |
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/ |
53 |
|
Also available in: Unified diff