From 91ecaf80b3959bc902c713bd8556757b296a2bd0 Mon Sep 17 00:00:00 2001 From: etienne Date: Wed, 20 Aug 2008 00:01:23 +0000 Subject: Internationalization of the application --- locale/fr/LC_MESSAGES/django.mo | Bin 0 -> 3196 bytes locale/fr/LC_MESSAGES/django.po | 188 ++++++++++++++++++++++++++++++++++++++++ polls/models.py | 23 ++--- polls/views.py | 85 +++++++++++------- static/styles.css | 26 ++++++ templates/base.html | 6 ++ templates/createOrEdit.html | 45 +++++----- templates/main.html | 6 +- templates/vote.html | 7 +- 9 files changed, 316 insertions(+), 70 deletions(-) create mode 100644 locale/fr/LC_MESSAGES/django.mo create mode 100644 locale/fr/LC_MESSAGES/django.po diff --git a/locale/fr/LC_MESSAGES/django.mo b/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 0000000..8812e42 Binary files /dev/null and b/locale/fr/LC_MESSAGES/django.mo differ diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..b8bf7b5 --- /dev/null +++ b/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,188 @@ +# Papillon +# Copyright (C) 2008 +# This file is distributed under the same license as the papillon package. +# Étienne Loks , 2008. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: 0.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2008-08-20 00:40+0200\n" +"PO-Revision-Date: 2008-08-20 00:22+0200\n" +"Last-Translator: Étienne Loks ,\n" +"Language-Team: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: settings.py:89 +msgid "French" +msgstr "Français" + +#: settings.py:90 +msgid "English" +msgstr "Anglais" + +#: templates/vote.html:21 templates/vote.html.py:41 +#: templates/createOrEdit.html:63 +msgid "Edit" +msgstr "Modifier" + +#: templates/vote.html:35 +msgid "Sum" +msgstr "Somme" + +#: templates/vote.html:41 +msgid "Participate" +msgstr "Participer" + +#: templates/createOrEdit.html:6 +msgid "" +"As long as no options were added to the poll, it will not be made available." +msgstr "" +"Tant qu'aucune option ne sera ajouté au sondage, il ne sera pas disponible." + +#: templates/createOrEdit.html:8 +msgid "New poll" +msgstr "Nouveau sondage" + +#: templates/createOrEdit.html:8 +msgid "Edit poll" +msgstr "Éditer un sondage" + +#: templates/createOrEdit.html:13 +msgid "Poll url" +msgstr "Adresse du sondage" + +#: templates/createOrEdit.html:15 +msgid "" +"Copy this address and send it to voters who want to participate to this poll" +msgstr "Copiez cette adresse et envoyez là aux participants à ce sondage." + +#: templates/createOrEdit.html:18 +msgid "Administration url" +msgstr "Adresse d'administration" + +#: templates/createOrEdit.html:20 +msgid "Address to modify the current poll" +msgstr "Adresse de modification de ce sondage" + +#: templates/createOrEdit.html:23 polls/views.py:56 +msgid "Author name" +msgstr "Nom de l'auteur" + +#: templates/createOrEdit.html:25 +msgid "Name, firstname or nickname of the author" +msgstr "Nom, prénom ou surnom de l'auteur" + +#: templates/createOrEdit.html:28 polls/views.py:57 +msgid "Poll name" +msgstr "Nom du sondage" + +#: templates/createOrEdit.html:30 +msgid "Global name to present the poll" +msgstr "Nom général pour présenter le sondage" + +#: templates/createOrEdit.html:33 polls/views.py:58 +msgid "Poll description" +msgstr "Description du sondage" + +#: templates/createOrEdit.html:35 +msgid "Precise description of the poll" +msgstr "Description précise du sondage" + +#: templates/createOrEdit.html:38 polls/views.py:59 +msgid "Poll type" +msgstr "Type du sondage" + +#: templates/createOrEdit.html:42 +msgid "Type of the poll:" +msgstr "Type du sondage :" + +#: templates/createOrEdit.html:44 +msgid "Meeting is the appropriate type to set a date for a meeting." +msgstr "Réunion est le type adéquat pour trouver une date pour une réunion" + +#: templates/createOrEdit.html:45 +msgid "Poll is the appropriate type for a simple multi-choice poll" +msgstr "Sondage est le type adéquat pour un simple sondage à choix multiple" + +#: templates/createOrEdit.html:46 +msgid "Balanced poll lets voters setting negative vote for some choices" +msgstr "" +"Sondage pondéré permet aux participants de mettre des votes négatifs pour " +"certains choix" + +#: templates/createOrEdit.html:47 polls/models.py:27 +msgid "One choice poll" +msgstr "Sondage à choix unique" + +#: templates/createOrEdit.html:53 +msgid "Choices" +msgstr "Choix" + +#: templates/createOrEdit.html:53 +msgid "Delete?" +msgstr "Supprimer ?" + +#: templates/createOrEdit.html:58 +msgid "New choice" +msgstr "Nouveau choix" + +#: templates/createOrEdit.html:61 +msgid "Create" +msgstr "Créer" + +#: templates/main.html:6 +msgid "Create a poll" +msgstr "Créer un sondage" + +#: templates/main.html:7 +msgid "" +"Create a new sondage for take a decision, find a date for a meeting, etc." +msgstr "" +"Créer un nouveau sondage pour prendre une décision, trouver une date pour " +"une réunion, etc." + +#: polls/models.py:21 +msgid "Available" +msgstr "Disponible" + +#: polls/models.py:22 +msgid "Disabled" +msgstr "Indisponible" + +#: polls/models.py:24 +msgid "Meeting" +msgstr "Réunion" + +#: polls/models.py:25 +msgid "Poll" +msgstr "Sondage" + +#: polls/models.py:26 +msgid "Balanced poll" +msgstr "Sondage pondéré" + +#: polls/models.py:47 +msgid "No" +msgstr "Non" + +#: polls/models.py:48 +msgid "Maybe" +msgstr "Peut-être" + +#: polls/models.py:49 +msgid "Yes" +msgstr "Oui" + +#: polls/views.py:32 +msgid "The poll requested don't exist (anymore?)" +msgstr "Le sondage que vous avez demandé n'existe pas (n'existe plus ?)" + +#: polls/views.py:66 +#, python-format +msgid "%s is a mandatory field" +msgstr "%s est un champs obligatoire" + diff --git a/polls/models.py b/polls/models.py index 08395b8..6e9c9bd 100644 --- a/polls/models.py +++ b/polls/models.py @@ -5,6 +5,7 @@ # See the file COPYING. from django.db import models +from django.utils.translation import gettext_lazy as _ class PollUser(models.Model): name = models.CharField(maxlength=100) @@ -17,19 +18,19 @@ class Poll(models.Model): author = models.ForeignKey(PollUser) base_url = models.CharField(maxlength=100) admin_url = models.CharField(maxlength=100) - STATUS = (('A', 'Available'), - ('D', 'Disabled'),) + STATUS = (('A', _('Available')), + ('D', _('Disabled')),) status = models.CharField(maxlength=1, choices=STATUS) - TYPE = (('M', 'Meeting'), - ('P', 'Poll'), - ('B', 'Balanced poll'), - ('O', 'One choice poll'),) + TYPE = (('M', _('Meeting')), + ('P', _('Poll')), + ('B', _('Balanced poll')), + ('O', _('One choice poll')),) type = models.CharField(maxlength=1, choices=TYPE) - + def getTypeLabel(self): idx = [type[0] for type in self.TYPE].index(self.type) return Poll.TYPE[idx][1] - + class Admin: pass @@ -43,8 +44,8 @@ class Choice(models.Model): class Vote(models.Model): voter = models.ForeignKey(PollUser) choice = models.ForeignKey(Choice) - VOTE = ((-1, 'No'), - (0, 'Maybe'), - (1, 'Yes'),) + VOTE = ((-1, _('No')), + (0, _('Maybe')), + (1, _('Yes')),) value = models.IntegerField(choices=VOTE) diff --git a/polls/views.py b/polls/views.py index 219590c..4e3400b 100644 --- a/polls/views.py +++ b/polls/views.py @@ -4,27 +4,46 @@ # This program can be distributed under the terms of the GNU GPL. # See the file COPYING. +''' +Views management +''' + from random import choice as random_choice import string import time +from django.utils.translation import gettext_lazy as _ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect +from papillon.settings import LANGUAGES from papillon.polls.models import Poll, PollUser, Choice, Vote def getBaseResponse(request): - "Get the root url in order to redirect to the main page" - url = "/".join([request.META['HTTP_HOST'], - request.path.split('/')[1], '']) - return {'root_url':url} + """Manage basic fields for the template + If not null the second argument returned is a redirection. + """ + #Get the root url in order to redirect to the main page + url = "/".join([request.META['HTTP_HOST'], + request.path.split('/')[1], '']) + # setting the current language and available languages + if 'language' in request.GET: + if request.GET['language'] in [language[0] for language in LANGUAGES]: + request.session['django_language'] = request.GET['language'] + return None, HttpResponseRedirect(request.path) + languages = [] + for language_code, language_label in LANGUAGES: + languages.append((language_code, _(language_label))) + return {'root_url':url, 'languages':languages}, None def index(request): "Main page" - response_dct = getBaseResponse(request) + response_dct, redirect = getBaseResponse(request) + if redirect: + return redirect error = '' if 'bad_poll' in request.GET: - response_dct['error'] = "The poll requested don't exist (anymore?)" + response_dct['error'] = _("The poll requested don't exist (anymore?)") return render_to_response('main.html', response_dct) def createOrEdit(request, admin_url): @@ -39,26 +58,26 @@ def createOrEdit(request, admin_url): def genRandomURL(): "Generation of a random url" chars = string.letters + string.digits - url = '' + url = '' for i in xrange(6): url += random_choice(chars) url += str(int(time.time())) return url - + def submitNewPoll(request, response_dct): "A new poll is submited" # verify if all the mandatory_fields are set - mandatory_fields = (('author_name', "Author name"), - ('poll_name', "Poll name"), - ('poll_desc', "Poll description"), - ('poll_type', "Poll type"), + mandatory_fields = (('author_name', _("Author name")), + ('poll_name', _("Poll name")), + ('poll_desc', _("Poll description")), + ('poll_type', _("Poll type")), ) error = "" for key, label in mandatory_fields: if key not in request.POST or not request.POST[key]: # only the first error is reported if not error: - error = "%s is a mandatory field" % label + error = _("%s is a mandatory field") % label else: response_dct[key] = request.POST[key] if error: @@ -76,7 +95,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) poll.save() url = response_dct['admin_url'] + '/%s/' % poll.admin_url return response_dct, HttpResponseRedirect(url) - + def getExistingPoll(request, response_dct, admin_url): "Get an existing poll" try: @@ -93,7 +112,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) 'poll_status':poll.status, 'type_name':poll.getTypeLabel()} response_dct.update(new_dct) - + # urls base_path = request.META['HTTP_HOST'] + \ "/".join(request.path.split('/')[:-3]) @@ -103,7 +122,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) response_dct['admin_url'] += '/%s/' % poll.admin_url response_dct['full_admin_url'] = base_path + "/edit/" \ + admin_url + "/" - + # if a new choice is submitted if 'new_choice' in request.POST and request.POST['new_choice']: try: @@ -112,17 +131,19 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) except IndexError: order = 0 choice = Choice(poll=poll, name=request.POST['new_choice'], - order=order) + order=order) choice.save() - # check if a choice has been choosen for deletion + # check if a choice has been choosen for deletion for key in request.POST: if key.startswith('delete_') and request.POST[key]: choice = Choice.objects.get(id=int(key[len('delete_'):])) Vote.objects.filter(choice=choice).delete() choice.delete() return response_dct, None - - response_dct = getBaseResponse(request) + + response_dct, redirect = getBaseResponse(request) + if redirect: + return redirect response_dct['TYPES'] = Poll.TYPE response_dct['admin_url'] = \ "/".join(request.path.split('/')[:-2]) @@ -136,7 +157,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) response_dct['admin_url'] += '/0/' else: # existing poll - response_dct, redirection = getExistingPoll(request, + response_dct, redirection = getExistingPoll(request, response_dct, admin_url) if redirection: return redirection @@ -147,7 +168,7 @@ def poll(request, poll_url): """Display a poll poll_url is given to identify the poll """ - + def modifyVote(request, choices): "Modify user's votes" try: @@ -155,7 +176,7 @@ def poll(request, poll_url): id=int(request.POST['voter']))[0] except (ValueError, IndexError): return - # if no author_name is given deletion of associated votes and + # if no author_name is given deletion of associated votes and # author if not request.POST['author_name']: for choice in choices: @@ -215,7 +236,7 @@ def poll(request, poll_url): author = PollUser(name=request.POST['author_name']) author.save() selected_choices = [] - + # set the selected choices for key in request.POST: if key.startswith('choice_') and request.POST[key]: @@ -236,7 +257,9 @@ def poll(request, poll_url): v = Vote(voter=author, choice=choice, value=0) v.save() - response_dct = getBaseResponse(request) + response_dct, redirect = getBaseResponse(request) + if redirect: + return redirect try: poll = Poll.objects.filter(base_url=poll_url)[0] except IndexError: @@ -244,11 +267,11 @@ def poll(request, poll_url): choices = Choice.objects.filter(poll=poll).order_by('order') # if the poll don't exist or if it has no choices the user is # redirected to the main page - if not choices or not poll: + if not choices or not poll: url = "/".join(request.path.split('/')[:-3]) url += "/?bad_poll=1" return HttpResponseRedirect(url) - + # a vote is submitted if 'author_name' in request.POST: if 'voter' in request.POST: @@ -256,27 +279,27 @@ def poll(request, poll_url): modifyVote(request, choices) else: newVote(request, choices) - + # 'voter' is in request.GET when the edit button is pushed if 'voter' in request.GET: try: response_dct['current_voter_id'] = int(request.GET['voter']) except ValueError: pass - + response_dct.update({'choices':choices, 'poll_type_name':poll.getTypeLabel(), 'poll_name':poll.name, 'poll_desc':poll.description}) response_dct['base_url'] = "/".join(request.path.split('/')[:-2]) \ + '/%s/' % poll.base_url - + # get voters and sum for each choice for this poll votes = [] # all votes for this poll votes = Vote.objects.extra(where=['choice_id IN (%s)' \ % ",".join([str(choice.id) for choice in choices])]) - + voters = [] choices_sum = [0 for choice in choices] choices_ids = [choice.id for choice in choices] diff --git a/static/styles.css b/static/styles.css index a5bd11e..126f807 100644 --- a/static/styles.css +++ b/static/styles.css @@ -11,6 +11,8 @@ background-color:#ced3e1; } h1, h1 a{ +margin:0; +margin-top:2px;; border:1px solid black; border-right:None; border-left:None; @@ -58,6 +60,30 @@ background-repeat:no-repeat; background-position:top right; } +#header{ +text-align:right; +font-size:11px; +color:grey; +} + +#header #languages a{ +color:grey; +padding-right:6px; +text-decoration:none; +} + +#footer{ +text-align:center; +font-size:11px; +color:grey; +margin:6px; +} + +#footer a{ +color:grey; +text-decoration:none; +} + .error{ color:red; } diff --git a/templates/base.html b/templates/base.html index 53bc3cf..3f4dec6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,12 +8,18 @@
+
{% block content %}{% endblock %}
+
diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html index 073dcfd..12d9d9d 100644 --- a/templates/createOrEdit.html +++ b/templates/createOrEdit.html @@ -1,64 +1,65 @@ +{% load i18n %} {% extends "base.html" %} {% block content %} {% if not new and not choices %} -

As long as no options were added to the poll, it will not be made available.

+

{% trans "As long as no options were added to the poll, it will not be made available." %}

{% endif %} -

{% if new %}New{% else %}Edit{% endif %} poll

+

{% if new %}{% trans "New poll" %}{% else %}{% trans "Edit poll" %}{% endif %}

{% if error %}

{{ error }}

{% endif %}
{% if not new %} - + - + - + - + {% endif %} - + - + - + - + - + - + {% if not new %}{% if choices %} - + {% for choice in choices %} - {% endfor %}{% endif %} + {% endfor %}{% endif %} {% endif %}
http://{{full_base_url}}Copy this address and send it to voters who want to participate to this poll{% trans "Copy this address and send it to voters who want to participate to this poll" %}
http://{{full_admin_url}}Address to modify the current poll{% trans "Address to modify the current poll" %}
{% if new %}{% else %}{{author_name}}{% endif %}Name, firstname or nickname of the author{% trans "Name, firstname or nickname of the author" %}
{% if new %}{% else %}{{poll_name}}{% endif %}Global name to present the poll{% trans "Global name to present the poll" %}
{% if new %}{% else %}{{poll_desc}}{% endif %}Precise description of the poll{% trans "Precise description of the poll" %}
Choices Delete?{% trans "Choices" %} {% trans "Delete?"%}
 {{choice.name}}
{% if new %} - + {% else %} - + {% endif %}
{% endblock %} diff --git a/templates/main.html b/templates/main.html index 34f6609..0ca4536 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,9 +1,9 @@ +{% load i18n %} {% extends "base.html" %} {% block content %} {% if error %}

{{error}}

{%endif%} -

Create a poll

-

Create a new sondage for take a decision, find a date for a meeting, etc.

+

{% trans "Create a poll" %}

+

{% trans "Create a new sondage for take a decision, find a date for a meeting, etc." %}

{% endblock %} - diff --git a/templates/vote.html b/templates/vote.html index 1b862c4..0174a18 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -1,3 +1,4 @@ +{% load i18n %} {% extends "base.html" %} {% block content %} @@ -17,7 +18,7 @@ {% for vote in voter.votes %}{%endfor%} - {%else%}Edit + {%else%}{% trans "Edit" %} {{voter.name}} {% for vote in voter.votes %}{% ifequal vote.value 1%}Yes{%else%}No{%endifequal%} {%endfor%} @@ -31,12 +32,12 @@ {%endif%} - Sum + {% trans "Sum" %} {% for sum in choices_sum %}{{sum}} {% endfor %} - + {% endblock %} -- cgit v1.2.3