Skip to content

Commit

Permalink
Applied a patch from Steffen Hoffmann which enables i18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
itota committed May 23, 2010
1 parent cb202be commit 20d9f23
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 13 deletions.
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,24 @@
[egg_info] [egg_info]
tag_build = .dev tag_build = .dev
tag_date = True tag_date = True

[extract_messages]
add_comments = TRANSLATOR:
msgid_bugs_address = hoff.st@web.de
output_file = tracsubtickets/locale/messages.pot
keywords = _ ngettext:1,2 N_ tag_
width = 72

[init_catalog]
input_file = tracsubtickets/locale/messages.pot
output_dir = tracsubtickets/locale
domain = tracsubtickets

[compile_catalog]
directory = tracsubtickets/locale
domain = tracsubtickets

[update_catalog]
input_file = tracsubtickets/locale/messages.pot
output_dir = tracsubtickets/locale
domain = tracsubtickets
16 changes: 13 additions & 3 deletions setup.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# #
# Copyright (c) 2010, Takashi Ito # Copyright (c) 2010, Takashi Ito
# i18n and German translation by Steffen Hoffmann
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,20 +32,30 @@


setup( setup(
name = 'TracSubTicketsPlugin', name = 'TracSubTicketsPlugin',
version = '0.1.0', version = '0.1.1',
keywords = 'trac plugin ticket subticket', keywords = 'trac plugin ticket subticket',
author = 'Takashi Ito', author = 'Takashi Ito',
author_email = 'TakashiC.Ito@gmail.com', author_email = 'TakashiC.Ito@gmail.com',
url = 'http://github.com/itota/trac-subtickets-plugin', url = 'http://github.com/itota/trac-subtickets-plugin',
description = 'Trac Sub-Tickets Plugin', description = 'Trac Sub-Tickets Plugin',
long_description = """
This plugin for Trac 0.12 provides Sub-Tickets functionality.
The association is done by adding parent tickets number to a custom field.
Checks ensure i.e. resolving of sub-tickets before closing the parent.
Babel is required to display localized texts.
Currently only translation for de_DE is provided.
"""
license = 'BSD', license = 'BSD',


install_requires = ['Trac'], install_requires = ['Trac >= 0.12dev'],


packages = find_packages(exclude=['*.tests*']), packages = find_packages(exclude=['*.tests*']),
package_data = { package_data = {
'tracsubtickets': [ 'tracsubtickets': [
'htdocs/css/*.css', 'htdocs/css/*.css',
'locale/*.*',
'locale/*/LC_MESSAGES/*.*',
], ],
}, },
entry_points = { entry_points = {
Expand All @@ -57,4 +68,3 @@
], ],
}, },
) )

27 changes: 22 additions & 5 deletions tracsubtickets/api.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,24 +29,41 @@


import re import re


import pkg_resources

from trac.core import * from trac.core import *
from trac.env import IEnvironmentSetupParticipant from trac.env import IEnvironmentSetupParticipant
from trac.db import DatabaseManager from trac.db import DatabaseManager
from trac.ticket.model import Ticket from trac.ticket.model import Ticket
from trac.ticket.api import ITicketChangeListener, ITicketManipulator from trac.ticket.api import ITicketChangeListener, ITicketManipulator


from trac.util.translation import domain_functions


import db_default import db_default




NUMBERS_RE = re.compile(r'\d+', re.U) NUMBERS_RE = re.compile(r'\d+', re.U)


# i18n support for plugins, available since Trac r7705
# use _, tag_ and N_ as usual, e.g. _("this is a message text")
_, tag_, N_, add_domain = domain_functions('tracsubtickets',
'_', 'tag_', 'N_', 'add_domain')



class SubTicketsSystem(Component): class SubTicketsSystem(Component):


implements(IEnvironmentSetupParticipant, implements(IEnvironmentSetupParticipant,
ITicketChangeListener, ITicketChangeListener,
ITicketManipulator) ITicketManipulator)


def __init__(self):
self._version = None
self.ui = None
# bind the 'traccsubtickets' catalog to the locale directory
locale_dir = pkg_resources.resource_filename(__name__, 'locale')
add_domain(self.env.path, locale_dir)

# IEnvironmentSetupParticipant methods # IEnvironmentSetupParticipant methods
def environment_created(self): def environment_created(self):
self.found_db_version = 0 self.found_db_version = 0
Expand Down Expand Up @@ -159,13 +176,13 @@ def validate_ticket(self, req, ticket):
myid = str(ticket.id) myid = str(ticket.id)
for id in _ids: for id in _ids:
if id == myid: if id == myid:
yield 'parents', 'A ticket cannot be a parent to itself' yield 'parents', _('A ticket cannot be a parent to itself')
else: else:
# check if the id exists # check if the id exists
cursor.execute("SELECT id FROM ticket WHERE id=%s", (id, )) cursor.execute("SELECT id FROM ticket WHERE id=%s", (id, ))
row = cursor.fetchone() row = cursor.fetchone()
if row is None: if row is None:
yield 'parents', 'Ticket #%s does not exist' % id yield 'parents', _('Ticket #%s does not exist') % id
ids.append(id) ids.append(id)


# circularity check function # circularity check function
Expand All @@ -176,7 +193,7 @@ def _check_parents(id, all_parents):
for x in [int(x[0]) for x in cursor]: for x in [int(x[0]) for x in cursor]:
if x in all_parents: if x in all_parents:
error = ' > '.join(['#%s' % n for n in all_parents + [x]]) error = ' > '.join(['#%s' % n for n in all_parents + [x]])
errors.append(('parents', 'Circularity error: %s' % error)) errors.append(('parents', _('Circularity error: %s') % error))
else: else:
errors += _check_parents(x, all_parents) errors += _check_parents(x, all_parents)
return errors return errors
Expand All @@ -185,7 +202,7 @@ def _check_parents(id, all_parents):
# check parent ticket state # check parent ticket state
parent = Ticket(self.env, x) parent = Ticket(self.env, x)
if parent and parent['status'] == 'closed': if parent and parent['status'] == 'closed':
yield 'parents', 'Parent ticket #%s is closed' % x yield 'parents', _('Parent ticket #%s is closed') % x
else: else:
# check circularity # check circularity
all_parents = ticket.id and [ticket.id] or [] all_parents = ticket.id and [ticket.id] or []
Expand All @@ -196,5 +213,5 @@ def _check_parents(id, all_parents):


except Exception, e: except Exception, e:
self.log.error(e) self.log.error(e)
yield 'parents', 'Not a valid list of ticket IDs' yield 'parents', _('Not a valid list of ticket IDs')


61 changes: 61 additions & 0 deletions tracsubtickets/locale/de_DE/LC_MESSAGES/tracsubtickets.po
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,61 @@
# translation of tracsubtickets.po to German
# German (Germany) translations for TracSubTicketsPlugin.
# Copyright (C) 2010
# This file is distributed under the same license as the
# TracSubTicketsPlugin project.
#
# Steffen Hoffmann <hoff.st@web.de>, 2010.
msgid ""
msgstr ""
"Project-Id-Version: TracSubTicketsPlugin 0.1.x\n"
"Report-Msgid-Bugs-To: hoff.st@web.de\n"
"POT-Creation-Date: 2010-05-04 01:38+0200\n"
"PO-Revision-Date: 2010-05-04 01:48+0200\n"
"Last-Translator: Steffen Hoffmann <hoff.st@web.de>\n"
"Language-Team: German de_DE <trac-dev@googlegroups.com>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.0dev-r482\n"

#: tracsubtickets/api.py:179
msgid "A ticket cannot be a parent to itself"
msgstr "Ein Ticket kann nicht sein eigener Vorläufer sein"

#: tracsubtickets/api.py:185
#, python-format
msgid "Ticket #%s does not exist"
msgstr "Ticket #%s ist nicht vorhanden"

#: tracsubtickets/api.py:196
#, python-format
msgid "Circularity error: %s"
msgstr "Zirkelbezug: %s"

#: tracsubtickets/api.py:205 tracsubtickets/web_ui.py:129
#, python-format
msgid "Parent ticket #%s is closed"
msgstr "Das Vorgänger-Ticket #%s ist geschossen"

#: tracsubtickets/api.py:216
msgid "Not a valid list of ticket IDs"
msgstr "Keine gültige Liste von Ticket-IDs"

#: tracsubtickets/web_ui.py:123
#, python-format
msgid "Child ticket #%s has not been closed yet"
msgstr "Folge-Ticket #%s wurde bisher noch nicht geschlossen"

#: tracsubtickets/web_ui.py:141
msgid "add"
msgstr "hinzufügen"

#: tracsubtickets/web_ui.py:143
msgid "Create new child ticket"
msgstr "Neues Folge-Ticket erstellen"

#: tracsubtickets/web_ui.py:147
msgid "Subtickets "
msgstr "Folge-Tickets "

60 changes: 60 additions & 0 deletions tracsubtickets/locale/messages.pot
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,60 @@
# Translations template for TracSubTicketsPlugin.
# Copyright (C) 2010 ORGANIZATION
# This file is distributed under the same license as the
# TracSubTicketsPlugin project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: TracSubTicketsPlugin 0.1.x\n"
"Report-Msgid-Bugs-To: hoff.st@web.de\n"
"POT-Creation-Date: 2010-05-04 01:38+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <trac-dev@googlegroups.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.0dev-r482\n"

#: tracsubtickets/api.py:179
msgid "A ticket cannot be a parent to itself"
msgstr ""

#: tracsubtickets/api.py:185
#, python-format
msgid "Ticket #%s does not exist"
msgstr ""

#: tracsubtickets/api.py:196
#, python-format
msgid "Circularity error: %s"
msgstr ""

#: tracsubtickets/api.py:205 tracsubtickets/web_ui.py:129
#, python-format
msgid "Parent ticket #%s is closed"
msgstr ""

#: tracsubtickets/api.py:216
msgid "Not a valid list of ticket IDs"
msgstr ""

#: tracsubtickets/web_ui.py:123
#, python-format
msgid "Child ticket #%s has not been closed yet"
msgstr ""

#: tracsubtickets/web_ui.py:141
msgid "add"
msgstr ""

#: tracsubtickets/web_ui.py:143
msgid "Create new child ticket"
msgstr ""

#: tracsubtickets/web_ui.py:147
msgid "Subtickets "
msgstr ""

12 changes: 7 additions & 5 deletions tracsubtickets/web_ui.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from genshi.builder import tag from genshi.builder import tag
from genshi.filters import Transformer from genshi.filters import Transformer


from api import NUMBERS_RE from api import NUMBERS_RE, _




class SubTicketsModule(Component): class SubTicketsModule(Component):
Expand Down Expand Up @@ -120,13 +120,13 @@ def validate_ticket(self, req, ticket):


for parent, child in cursor: for parent, child in cursor:
if Ticket(self.env, child)['status'] != 'closed': if Ticket(self.env, child)['status'] != 'closed':
yield None, 'Child ticket #%s has not been closed yet' % child yield None, _('Child ticket #%s has not been closed yet') % child


elif action == 'reopen': elif action == 'reopen':
ids = set(NUMBERS_RE.findall(ticket['parents'] or '')) ids = set(NUMBERS_RE.findall(ticket['parents'] or ''))
for id in ids: for id in ids:
if Ticket(self.env, id)['status'] == 'closed': if Ticket(self.env, id)['status'] == 'closed':
yield None, 'Parent ticket #%s is closed' % id yield None, _('Parent ticket #%s is closed') % id


# ITemplateStreamFilter method # ITemplateStreamFilter method
def filter_stream(self, req, method, filename, stream, data): def filter_stream(self, req, method, filename, stream, data):
Expand All @@ -138,11 +138,13 @@ def filter_stream(self, req, method, filename, stream, data):
# title # title
div = tag.div(class_='description') div = tag.div(class_='description')
if ticket['status'] != 'closed': if ticket['status'] != 'closed':
link = tag.a('add', href=req.href.newticket(parents=ticket.id)) link = tag.a(_('add'),
href=req.href.newticket(parents=ticket.id),
title=_('Create new child ticket'))
link = tag.span('(', link, ')', class_='addsubticket') link = tag.span('(', link, ')', class_='addsubticket')
else: else:
link = None link = None
div.append(tag.h3('Subtickets ', link)) div.append(tag.h3(_('Subtickets '), link))


if 'subtickets' in data: if 'subtickets' in data:
# table # table
Expand Down

0 comments on commit 20d9f23

Please sign in to comment.