[damned-lies] Prepare empty po files with guessable values (Bug #573814)
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Subject: [damned-lies] Prepare empty po files with guessable values (Bug #573814)
- Date: Tue, 26 May 2009 03:43:52 -0400 (EDT)
commit 5a01f792ad68aad81e6234b5aa4a8d67a1037cbd
Author: Claude Paroz <claude 2xlibre net>
Date: Sun May 24 00:06:15 2009 +0200
Prepare empty po files with guessable values (Bug #573814)
Instead of merely offering the POT file for a new translation, try
to guess values an fill placeholders with these values, when they
are available (package name, language, mailing_list, year, etc.)
---
stats/views.py | 55 ++++++++++++++++++++++++++++++-
templates/vertimus/vertimus_detail.html | 2 +-
urls.py | 1 +
vertimus/views.py | 4 ++
4 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/stats/views.py b/stats/views.py
index c7e62db..0a131c1 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -17,18 +17,20 @@
# You should have received a copy of the GNU General Public License
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from datetime import date
from django.conf import settings
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.core import serializers
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
from django.template import RequestContext
from django.utils.translation import ugettext as _
from stats.models import Statistics, Module, Branch, Category, Release
from stats.forms import ModuleBranchForm
from stats import utils
+from languages.models import Language
MIME_TYPES = {'json': 'application/json',
'xml': 'text/xml'
@@ -154,6 +156,57 @@ def docimages(request, module_name, potbase, branch_name, langcode):
}
return render_to_response('module_images.html', context, context_instance=RequestContext(request))
+def dynamic_po(request, filename):
+ """ Generates a dynamic po file from the POT file of a branch """
+ try:
+ module, domain, branch, locale, ext = filename.split(".")
+ language = Language.objects.select_related('team').get(locale=locale)
+ except:
+ raise Http404
+ potfile = get_object_or_404(Statistics,
+ branch__module__name=module,
+ branch__name=branch,
+ domain__name=domain,
+ language=None)
+ file_path = potfile.po_path()
+ f = open(file_path)
+
+ dyn_content = """# %(lang)s translation of %(pack)s.
+# Copyright (C) %(year)s %(pack)s's COPYRIGHT HOLDER
+# This file is distributed under the same license as the %(pack)s package.\n""" % {
+ 'lang': language.name,
+ 'pack': module,
+ 'year': date.today().year
+ }
+ if request.user.is_authenticated():
+ person = request.user.person
+ dyn_content += "# %(name)s <%(email)s>, %(year)s.\n#\n" % {
+ 'name' : person.name,
+ 'email': person.email,
+ 'year' : date.today().year,
+ }
+ else:
+ dyn_content += "# FIRST AUTHOR <EMAIL ADDRESS>, YEAR.\n#\n"
+
+ line = "1"
+ while line:
+ line = f.readline()
+ if line and line[0] == '#':
+ # Skip first lines of the file
+ continue
+ # Transformations
+ line = {
+ '"Project-Id-': "\"Project-Id-Version: %s %s\\n\"\n" % (module, branch),
+ '"Language-Te': "\"Language-Team: %s <%s>\\n\"\n" % (
+ language.name, language.team and language.team.mailing_list or "%s li org" % locale),
+ '"Content-Typ': "\"Content-Type: text/plain; charset=UTF-8\\n\"\n",
+ '"Plural-Form': "\"Plural-Forms: %s;\\n\"\n" % (language.plurals or "nplurals=INTEGER; plural=EXPRESSION"),
+ }.get(line[:12], line)
+ dyn_content += line
+ if line == "\n":
+ break # Quit loop on first blank line after headers
+ return HttpResponse(dyn_content + f.read(), 'text/plain')
+
def releases(request, format='html'):
all_releases = Release.objects.order_by('status', '-name')
if format in ('json', 'xml'):
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index cd43cf6..8be96ea 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -36,7 +36,7 @@
<div style="line-height: 1.7">
<em><a href="{{ stats.pot_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a> {{ stats.pot_text }}</em><br />
-<a href="{{ stats.po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download PO file" %}" /></a> {% trans "Translated:" %}
+<a href="{{ po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download PO file" %}" /></a> {% trans "Translated:" %}
{{ stats.get_translationstat|safe }}
<div class="graph graphinline">
<div class="translated" style="width: {{ stats.tr_percentage }}px;"></div>
diff --git a/urls.py b/urls.py
index 90a75d1..f67119f 100644
--- a/urls.py
+++ b/urls.py
@@ -27,6 +27,7 @@ urlpatterns = patterns('',
urlpatterns += patterns('stats.views',
url(r'^module/$', 'modules', name='modules'),
+ url(r'^module/po/(?P<filename>.*)$', 'dynamic_po', name='dynamic_po'),
(r'^module/(?P<module_name>[\w\-\+]+)/$', 'module'),
(r'^module/(?P<module_name>[\w\-\+]+)/edit/branches/$', 'module_edit_branches'),
(r'^module/(?P<module_name>[\w\-\+]+)/branch/(?P<branch_name>[\w-]+)/$', 'module_branch'),
diff --git a/vertimus/views.py b/vertimus/views.py
index 7ea4429..f888bae 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -56,9 +56,12 @@ def vertimus(request, branch, domain, language, stats=None):
if not stats:
try:
stats = Statistics.objects.get(branch=branch, domain=domain, language=language)
+ po_url = stats.po_url()
except Statistics.DoesNotExist:
# Get the POT file stats
stats = get_object_or_404(Statistics, branch=branch, domain=domain, language=None)
+ po_url = urlresolvers.reverse('dynamic_po',
+ args=("%s.%s.%s.%s.po" % (branch.module.name, domain.name, branch.name, language.locale),))
# Get the state of the translation
(state_db, created) = StateDb.objects.get_or_create(
@@ -98,6 +101,7 @@ def vertimus(request, branch, domain, language, stats=None):
context = {
'pageSection': 'module',
'stats': stats,
+ 'po_url': po_url,
'branch': branch,
'other_states': other_branch_states,
'domain': domain,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]