diff --git a/.gitignore b/.gitignore index bd2c6c8..4c1c131 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ HudsonTrac.egg-info .svn *~ *.bak +*.mo diff --git a/HudsonTrac/HudsonTracPlugin.py b/HudsonTrac/HudsonTracPlugin.py index 16d0fbb..5909ff3 100644 --- a/HudsonTrac/HudsonTracPlugin.py +++ b/HudsonTrac/HudsonTracPlugin.py @@ -16,6 +16,8 @@ from xml.dom import minidom from datetime import datetime +from pkg_resources import resource_filename + from genshi.builder import tag from trac.core import * @@ -23,12 +25,15 @@ from trac.perm import IPermissionRequestor from trac.util.datefmt import format_datetime, pretty_timedelta, to_timestamp from trac.util.text import unicode_quote +from trac.util.translation import domain_functions from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet from trac.timeline.api import ITimelineEventProvider +add_domain, _, tag_ = domain_functions('hudsontrac', 'add_domain', '_', 'tag_') class HudsonTracPlugin(Component): - """Display Hudson results in the timeline and an entry in the main navigation bar. + """Display Hudson results in the timeline and an entry in the main + navigation bar. """ implements(INavigationContributor, ITimelineEventProvider, @@ -63,6 +68,12 @@ class HudsonTracPlugin(Component): messages.""") def __init__(self): + # i18n + add_domain(self.env.path, resource_filename(__name__, 'locale')) + self.log.info("Added domain 'hudsontrac' -> %s", + resource_filename(__name__, 'locale')) + + # prepare self.info_url api_url = unicode_quote(self.job_url, '/%:@') if api_url and api_url[-1] != '/': api_url += '/' @@ -113,7 +124,7 @@ def get_active_navigation_item(self, req): def get_navigation_items(self, req): if self.nav_url and req.perm.has_permission('BUILD_VIEW'): - yield 'mainnav', 'builds', tag.a("Build", href=self.nav_url, + yield 'mainnav', 'builds', tag.a(_("Build"), href=self.nav_url, target=self.disp_tab and "hudson" or None) # ITemplateProvider methods @@ -124,14 +135,13 @@ def get_templates_dirs(self): self.config.get('trac', 'templates_dir')] def get_htdocs_dirs(self): - from pkg_resources import resource_filename return [('HudsonTrac', resource_filename(__name__, 'htdocs'))] # ITimelineEventProvider methods def get_timeline_filters(self, req): if 'BUILD_VIEW' in req.perm: - yield ('build', 'Hudson Builds') + yield ('build', _('Hudson Builds')) def get_timeline_events(self, req, start, stop, filters): if 'build' not in filters or 'BUILD_VIEW' not in req.perm: @@ -194,21 +204,22 @@ def get_number(parent, child): result = get_string(entry, 'result') message, kind = { - 'SUCCESS': ('Build finished successfully', + 'SUCCESS': (_('Build finished successfully'), ('build-successful', 'build-successful-alt')[self.alt_succ]), - 'UNSTABLE': ('Build unstable', 'build-unstable'), - 'ABORTED': ('Build aborted', 'build-aborted'), - }.get(result, ('Build failed', 'build-failed')) + 'UNSTABLE': (_('Build unstable'), 'build-unstable'), + 'ABORTED': (_('Build aborted'), 'build-aborted'), + }.get(result, (_('Build failed'), 'build-failed')) if self.use_desc: message = get_string(entry, 'description') or message - comment = "%s at %s, duration %s" % ( - message, format_datetime(completed), - pretty_timedelta(started, completed)) + comment = _("%(message)s after %(elapsed)s", + message=message, + elapsed=pretty_timedelta(started, completed)) href = get_string(entry, 'url') - title = 'Build "%s" (%s)' % (get_string(entry, 'fullDisplayName'), - result.lower()) + title = tag_('Build %(name)s (%(result)s)', + name=tag.em(get_string(entry, 'fullDisplayName')), + result=result.lower()) yield kind, href, title, completed, None, comment diff --git a/HudsonTrac/locale/fr/LC_MESSAGES/hudsontrac.po b/HudsonTrac/locale/fr/LC_MESSAGES/hudsontrac.po new file mode 100644 index 0000000..aad9dda --- /dev/null +++ b/HudsonTrac/locale/fr/LC_MESSAGES/hudsontrac.po @@ -0,0 +1,53 @@ +# French translations for HudsonTrac. +# This file is distributed under the same license as the HudsonTrac +# project. +# Christian Boos , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: HudsonTrac 0.12.0.4\n" +"Report-Msgid-Bugs-To: cboos@neuf.fr\n" +"POT-Creation-Date: 2010-04-27 11:35+0200\n" +"PO-Revision-Date: 2010-04-27 11:42+0200\n" +"Last-Translator: Christian Boos \n" +"Language-Team: fr \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 0.9.5\n" + +#: HudsonTrac/HudsonTracPlugin.py:125 +msgid "Build" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:142 +msgid "Hudson Builds" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:205 +msgid "Build finished successfully" +msgstr "Le build a réussi" + +#: HudsonTrac/HudsonTracPlugin.py:208 +msgid "Build unstable" +msgstr "Le build est instable" + +#: HudsonTrac/HudsonTracPlugin.py:209 +msgid "Build aborted" +msgstr "Le build a été interrompu" + +#: HudsonTrac/HudsonTracPlugin.py:210 +msgid "Build failed" +msgstr "Le build a échoué" + +#: HudsonTrac/HudsonTracPlugin.py:217 +#, python-format +msgid "%(message)s after %(elapsed)s" +msgstr "%(message)s au bout de %(elapsed)s" + +#: HudsonTrac/HudsonTracPlugin.py:221 +#, python-format +msgid "Build %(name)s (%(result)s)" +msgstr "Build « %(name)s » (%(result)s)" + diff --git a/HudsonTrac/locale/messages.pot b/HudsonTrac/locale/messages.pot new file mode 100644 index 0000000..4f9584a --- /dev/null +++ b/HudsonTrac/locale/messages.pot @@ -0,0 +1,54 @@ +# Translations template for HudsonTrac. +# Copyright (C) 2010 ORGANIZATION +# This file is distributed under the same license as the HudsonTrac +# project. +# FIRST AUTHOR , 2010. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: HudsonTrac 0.12.0.4\n" +"Report-Msgid-Bugs-To: cboos@neuf.fr\n" +"POT-Creation-Date: 2010-04-27 11:35+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.5\n" + +#: HudsonTrac/HudsonTracPlugin.py:125 +msgid "Build" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:142 +msgid "Hudson Builds" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:205 +msgid "Build finished successfully" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:208 +msgid "Build unstable" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:209 +msgid "Build aborted" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:210 +msgid "Build failed" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:217 +#, python-format +msgid "%(message)s after %(elapsed)s" +msgstr "" + +#: HudsonTrac/HudsonTracPlugin.py:221 +#, python-format +msgid "Build %(name)s (%(result)s)" +msgstr "" + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e0ba2ef --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[egg_info] +tag_build = dev +tag_svn_revision = true + +[extract_messages] +add_comments = TRANSLATOR: +msgid_bugs_address = cboos@neuf.fr +output_file = HudsonTrac/locale/messages.pot +keywords = _ ngettext:1,2 N_ tag_ +width = 72 + +[init_catalog] +input_file = HudsonTrac/locale/messages.pot +output_dir = HudsonTrac/locale +domain = hudsontrac + +[compile_catalog] +directory = HudsonTrac/locale +domain = hudsontrac + +[update_catalog] +input_file = HudsonTrac/locale/messages.pot +output_dir = HudsonTrac/locale +domain = hudsontrac diff --git a/setup.py b/setup.py index 6eab922..5e29edf 100644 --- a/setup.py +++ b/setup.py @@ -3,20 +3,34 @@ from setuptools import setup +extra = {} + +try: + import babel + extra['message_extractors'] = { + 'HudsonTrac': [ + ('*.py', 'python', None), + ], + } +except ImportError: + pass + setup( name = 'HudsonTrac', - version = '0.11.0.3', + version = '0.12.0.4', author = "Ronald Tschalär", - description = "A trac plugin to add hudson build info to the trac timeline", + description = "Trac Plugin which adds Hudson build events to the timeline", license = "BSD", keywords = "trac builds hudson", url = "http://trac-hacks.org/wiki/HudsonTracPlugin", packages = ['HudsonTrac'], package_data = { - 'HudsonTrac' : ['htdocs/*.css', 'htdocs/*.gif'] + 'HudsonTrac' : ['htdocs/*.css', 'htdocs/*.gif', + 'locale/*.*', 'locale/*/LC_MESSAGES/*.*'], }, entry_points = { 'trac.plugins' : [ 'HudsonTrac = HudsonTrac.HudsonTracPlugin' ] - } + }, + **extra )