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