Commits

Tetsuya Morimoto  committed e73db06

added i18n/l10n support
added Japanese message catalog
changed to show localized message on templates

  • Participants
  • Parent commits 239e6b0

Comments (0)

Files changed (8)

 include bootstrap.py
 include MANIFEST.in
 include LICENSE
-recursive-include src *.py *.txt *.html *.css *.js *.png
+recursive-include ticketref *.py *.txt *.html *.css *.js *.png *.pot *.po *.mo
+# Adding i18n/l10n to Trac plugins (Trac >= 0.12)
+# see also: http://trac.edgewall.org/wiki/CookBook/PluginL10N
+[extract_messages]
+add_comments = TRANSLATOR: Tetsuya Morimoto
+msgid_bugs_address = http://trac-hacks.org/wiki/TracTicketReferencePlugin
+output_file = ticketref/locale/messages.pot
+keywords = _ N_ tag_
+width = 72
+
+[init_catalog]
+input_file = ticketref/locale/messages.pot
+output_dir = ticketref/locale
+domain = ticketref
+
+[compile_catalog]
+directory = ticketref/locale
+domain = ticketref
+
+[update_catalog]
+input_file = ticketref/locale/messages.pot
+output_dir = ticketref/locale
+domain = ticketref
     "Topic :: Software Development",
 ]
 
+EXTRA_PARAMETER = {}
+try:
+    # Adding i18n/l10n to Trac plugins (Trac >= 0.12)
+    # see also: http://trac.edgewall.org/wiki/CookBook/PluginL10N
+    from trac.util.dist import get_l10n_cmdclass
+    cmdclass = get_l10n_cmdclass()
+    if cmdclass:  # Yay, Babel is there, we"ve got something to do!
+        EXTRA_PARAMETER["cmdclass"] = cmdclass
+        EXTRA_PARAMETER["message_extractors"] = {
+            "ticketref": [
+                ("**.py", "python", None),
+            ]
+        }
+except ImportError:
+    pass
+
 setup(
     name="TracTicketReferencePlugin",
     version=VERSION,
     license="Apache License 2.0",
     packages=["ticketref"],
     package_data={
-        "ticketref": ["templates/*.html", "htdocs/*.js", "htdocs/*.css",
-                      "templates/*.png"],
+        "ticketref": [
+            "templates/*.html",
+            "htdocs/*.js",
+            "htdocs/*.css",
+            "templates/*.png",
+            "locale/*/LC_MESSAGES/*.po",
+            "locale/*/LC_MESSAGES/*.mo",
+        ],
     },
     include_package_data=True,
     install_requires=REQUIRES,
-    entry_points = {
+    entry_points={
         "trac.plugins": [
             "ticketref.web_ui = ticketref.web_ui",
             "ticketref.api = ticketref.api",
         ]
-    }
+    },
+    **EXTRA_PARAMETER
 )

File ticketref/api.py

 # -*- coding: utf-8 -*-
 
+from pkg_resources import resource_filename
+
 from trac.core import *
 from trac.env import IEnvironmentSetupParticipant
 from trac.ticket.api import ITicketChangeListener, ITicketManipulator
 from trac.ticket.model import Ticket
+from trac.util.translation import domain_functions
 
 from model import CUSTOM_FIELDS, TICKETREF, TicketLinks
 
+_, add_domain = domain_functions("ticketref", ("_", "add_domain"))
+
 
 class TicketRefsPlugin(Component):
     """ Extend custom field for ticket cross-reference """
     implements(IEnvironmentSetupParticipant,
                ITicketChangeListener, ITicketManipulator)
 
+    def __init__(self):
+        add_domain(self.env.path, resource_filename(__name__, "locale"))
+
     # IEnvironmentSetupParticipant methods
     def environment_created(self):
         self.upgrade_environment(self.env.get_db_cnx())
                     assert ref_id != ticket.id
                     Ticket(self.env, ref_id)
                 except AssertionError:
-                    msg = "Ticket %s is this ticket id, remove it." % ref_id
+                    msg = _("Ticket %s is this ticket id, remove it.") % ref_id
                     yield self.env.config.get(*_prop), msg
                 except Exception, err:
                     yield self.env.config.get(*_prop), err

File ticketref/locale/ja/LC_MESSAGES/ticketref.mo

Binary file added.

File ticketref/locale/ja/LC_MESSAGES/ticketref.po

+# Japanese translations for TracTicketReferencePlugin.
+# Copyright (C) 2012 ORGANIZATION
+# This file is distributed under the same license as the
+# TracTicketReferencePlugin project.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: TracTicketReferencePlugin 0.1.0\n"
+"Report-Msgid-Bugs-To: http://trac-"
+"hacks.org/wiki/TracTicketReferencePlugin\n"
+"POT-Creation-Date: 2012-01-17 17:16+0900\n"
+"PO-Revision-Date: 2012-01-17 16:07+0900\n"
+"Last-Translator: Tetsuya Morimoto\n"
+"Language-Team: ja <LL@li.org>\n"
+"Plural-Forms: nplurals=1; plural=0\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 0.9.6\n"
+
+#: ticketref/api.py:80
+#, python-format
+msgid "Ticket %s is this ticket id, remove it."
+msgstr "チケット %s はこのチケットなので削除してください。"
+
+#: ticketref/web_ui.py:59 ticketref/web_ui.py:72 ticketref/web_ui.py:82
+msgid "Relationships"
+msgstr "関連"
+
+#: ticketref/web_ui.py:115
+msgid "Open new ticket with relationships"
+msgstr "このチケットに関連付けて新しいチケットを登録する"
+

File ticketref/locale/messages.pot

+# Translations template for TracTicketReferencePlugin.
+# Copyright (C) 2012 ORGANIZATION
+# This file is distributed under the same license as the
+# TracTicketReferencePlugin project.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: TracTicketReferencePlugin 0.1.0\n"
+"Report-Msgid-Bugs-To: http://trac-"
+"hacks.org/wiki/TracTicketReferencePlugin\n"
+"POT-Creation-Date: 2012-01-17 17:16+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 0.9.6\n"
+
+#: ticketref/api.py:80
+#, python-format
+msgid "Ticket %s is this ticket id, remove it."
+msgstr ""
+
+#: ticketref/web_ui.py:59 ticketref/web_ui.py:72 ticketref/web_ui.py:82
+msgid "Relationships"
+msgstr ""
+
+#: ticketref/web_ui.py:115
+msgid "Open new ticket with relationships"
+msgstr ""
+

File ticketref/web_ui.py

 from trac.resource import ResourceNotFound
 from trac.ticket.model import Ticket
 from trac.util.text import shorten_line
+from trac.util.translation import domain_functions
 
 from model import TICKETREF as TREF
 from utils import cnv_text2list
 
+_, add_domain = domain_functions("ticketref", ("_", "add_domain"))
+
 TEMPLATE_FILES = [
     "report_view.html", "query_results.html", "ticket.html", "query.html",
 ]
 
     implements(ITemplateStreamFilter, ITemplateProvider)
 
+    def __init__(self):
+        add_domain(self.env.path, resource_filename(__name__, "locale"))
+
     # ITemplateStreamFilter methods
     def filter_stream(self, req, method, filename, stream, data):
         if not data or (not filename in TEMPLATE_FILES):
     def _filter_fields(self, req, data):
         for field in data["fields"]:
             if field["name"] == TREF:
+                field["label"] = _("Relationships")
                 ticket = data["ticket"]
                 new = self._link_new(req, ticket, field)
                 if ticket[TREF]:
                     field["rendered"] = tag([new])
 
     def _filter_groups(self, req, data):
+        for header in data["headers"]:
+            if header["name"] == TREF:
+                header["label"] = _("Relationships")
         for group, tickets in data["groups"]:
             for ticket in tickets:
                 if TREF in ticket:
                     ticket[TREF] = self._link_refs(req, ticket[TREF])
 
     def _filter_row_groups(self, req, data):
+        for headers in data["header_groups"]:
+            for header in headers:
+                if header["col"] == TREF:
+                    header["title"] = _("Relationships")
         for group, rows in data["row_groups"]:
             for row in rows:
                 _is_list = isinstance(row["cell_groups"], list)
             if ticket[field]:
                 param[field] = ticket[field]
         href = req.href.newticket(**param)
-        title = "Open new ticket with relationships"
+        title = _("Open new ticket with relationships")
         new_link = tag.a("+new", class_="", href=href, title=title)
         return new_link