Revision d7f0ad6e

b/README.i18n
1
DJANGO TRANSLATIONS OF STATIC TEXT
2

  
3
0)from our project's base, we add directory locale
4
$mkdir locale
5

  
6
then we add on the settings.py the language code
7
eg
8
LANGUAGES = (
9
  ('el', u'Ελληνικά'),
10
  ('en', 'English'),
11
)
12

  
13

  
14
1)for each language we want to add, we run makemessages, from our project's base:
15

  
16
$ django-admin.py makemessages -l el -e=html,txt,py
17

  
18
this will add the Greek language, and we specify that html, txt and python files contain translatable strings
19

  
20
2)we translate our strings. 
21
on .py files, (eg views.py), we add on the beggining of the file
22

  
23
from django.utils.translation import gettext_lazy as _
24

  
25
and then each string that needs translation becomes like this:  _('string')
26
eg
27

  
28
help_text=_("letters and numbers only"))
29
'title': _('Ubuntu 10.10 server 64bit'),
30

  
31

  
32
on django templates (html files), on the beggining of the file we add {% load i18n %} 
33
then on each string that needs to be translated, we put it on {% trans "string" %}, for example {% trans "Home" %}
34

  
35

  
36
3)when we have put our strings to be translated, from the project's base we run
37
$ django-admin.py makemessages -l el -e=html,txt,py
38
processing language el
39

  
40
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)
41

  
42
4)when we are ready, we run the following command from the project's base
43
$ django-admin.py compilemessages
44

  
45
this compiles the po files to mo. 
46

  
47
Our strings will appear translated once we change the language (eg from a dropdown menu in the page)
48

  
49
More info:
50
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
51

  
b/locale/el/LC_MESSAGES/django.po
1
# SOME DESCRIPTIVE TITLE.
2
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
# This file is distributed under the same license as the PACKAGE package.
4
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
#
6
#, fuzzy
7
msgid ""
8
msgstr ""
9
"Project-Id-Version: PACKAGE VERSION\n"
10
"Report-Msgid-Bugs-To: \n"
11
"POT-Creation-Date: 2011-01-07 18:19+0200\n"
12
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
"Language-Team: LANGUAGE <LL@li.org>\n"
15
"MIME-Version: 1.0\n"
16
"Content-Type: text/plain; charset=UTF-8\n"
17
"Content-Transfer-Encoding: 8bit\n"
18

  
19
#: ui/views.py:7
20
msgid "Ubuntu 10.10 server 64bit"
21
msgstr " Ένα Ubunty 10.10 mpla mpla "
22

  
23
#: ui/views.py:7
24
msgid "Apache, MySQL, php5 preinstalled"
25
msgstr ""
26

  
27
#: ui/templates/alt_instances.html:4 ui/templates/instances.html:3
28
msgid "Create New +"
29
msgstr "Δημιουργία Νέου +"
30

  
31
#: ui/templates/home.html:17
32
msgid "username"
33
msgstr ""
34

  
35
#: ui/templates/home.html:17
36
msgid "settings"
37
msgstr ""
38

  
39
#: ui/templates/home.html:34
40
msgid "Greek Research and Technology Network - Cloud management web interface"
41
msgstr "Εθνικό Δίκτυο Έρευνας και τεχνολογίας"
b/settings.py.dist
1
# -*- coding: utf-8 -*-
2

  
1 3
# Django settings for synnefo project.
2 4

  
3 5
DEBUG = True
......
70 72
#     'django.template.loaders.eggs.Loader',
71 73
)
72 74

  
75
TEMPLATE_CONTEXT_PROCESSORS = (
76
    'django.core.context_processors.i18n',
77
)
78

  
73 79
MIDDLEWARE_CLASSES = (
74 80
    'synnefo.middleware.StripURLMiddleware',
75 81
    'django.middleware.common.CommonMiddleware',
......
77 83
#    'django.middleware.csrf.CsrfViewMiddleware',
78 84
#    'django.contrib.auth.middleware.AuthenticationMiddleware',
79 85
    'django.contrib.messages.middleware.MessageMiddleware',
86
    'django.middleware.locale.LocaleMiddleware',
80 87
)
81 88

  
82 89
ROOT_URLCONF = 'synnefo.urls'
......
101 108
)
102 109

  
103 110
GANETI_CLUSTER_INFO = ('ganeti.example.org', 5080)
111

  
112
LANGUAGES = (
113
  ('el', u'Ελληνικά'),
114
  ('en', 'English'),
115
)
b/ui/templates/home.html
1
{% load i18n %}
2

  
1 3
<!DOCTYPE html>
2 4

  
3 5
<head>
......
11 13

  
12 14
<body>
13 15
    <div id="wrapper">
14
        <div id='user'><a href="#">username</a> &nbsp;|&nbsp; <a href="#">settings</a></div>
16

  
17
        <div id='user'><a href="#">{% trans "username" %}</a> &nbsp;|&nbsp; <a href="#">{% trans "settings" %}</a>
18
{% get_available_languages as LANGUAGES %}
19
<form action="/i18n/setlang/" method="post">
20
{% csrf_token %}
21
<input name="next" type="hidden" value="/" />
22
<select name="language">
23
{% for language in LANGUAGES %}
24
<option value="{{ language.0 }}">{{ language.1 }}::{{ language.0 }}</option>
25
{% endfor %}
26
</select>
27
<input type="submit" value="Go" />
28
</form>
29

  
30

  
31
</div>
15 32
        <div id='nefo'><a href="/" class="logo"><img src="static/nefo.png"/></a></div>
16 33
        <div id="header">
17
            <div id="about">Greek Research and Technology Network - Cloud management web interface</div>
34
            <div id="about">{% trans "Greek Research and Technology Network - Cloud management web interface" %}</div>
18 35
            <a href="/" class="logo">
19 36
                <h1>{{ project }}</h1>
20 37
            </a>
b/urls.py
6 6
from django.conf.urls.defaults import *
7 7

  
8 8
urlpatterns = patterns('',
9
    (r'^i18n/', include('django.conf.urls.i18n')),
9 10
    (r'^auth/api/', include('synnefo.auth.urls')),
10 11
    (r'^api/', include('synnefo.api.urls')),
11 12
    (r'^', include('synnefo.ui.urls')),

Also available in: Unified diff