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