namespace: introduce logfmt to show l10n-ed messages for hg log correctly stable
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 28 Jan 2015 22:22:59 +0900
branchstable
changeset 23967 448bb32b8ee6
parent 23966 2d2c0a8eeeb8
child 23968 6564ec382560
namespace: introduce logfmt to show l10n-ed messages for hg log correctly Before this patch, "_()" is used incorrectly for "tag:" and "bookmark:" fields. "changeset_printer()" looks up keys composed at runtime, and it prevents "xgettext" command from getting strings to be translated from source files. Then, *.po files merged with updated "hg.pot" lose msgids for "tag:" and "bookmark:". This patch introduces "logfmt" information into "namespace" to show l10n-ed messages "hg log" (or "changeset_printer()") correctly. For similarity to other namespaces, this patch specifies "logfmt" for "branches" namespace, even though it isn't needed (branch information is handled in "changeset_printer()" specially). To find related code paths out easily, this patch adds "i18n: column positioning ..." comment to the line composing "logfmt" by default, even though this line itself doesn't contain any strings to be translated.
mercurial/cmdutil.py
mercurial/namespaces.py
--- a/mercurial/cmdutil.py	Tue Jan 27 10:17:16 2015 -0500
+++ b/mercurial/cmdutil.py	Wed Jan 28 22:22:59 2015 +0900
@@ -919,9 +919,8 @@
             # we will use the templatename as the color name since those two
             # should be the same
             for name in ns.names(self.repo, changenode):
-                # i18n: column positioning for "hg log"
-                name = _(("%s:" % ns.logname).ljust(13) + "%s\n") % name
-                self.ui.write("%s" % name, label='log.%s' % ns.colorname)
+                self.ui.write(ns.logfmt % name,
+                              label='log.%s' % ns.colorname)
         if self.ui.debugflag:
             # i18n: column positioning for "hg log"
             self.ui.write(_("phase:       %s\n") % _(ctx.phasestr()),
--- a/mercurial/namespaces.py	Tue Jan 27 10:17:16 2015 -0500
+++ b/mercurial/namespaces.py	Wed Jan 28 22:22:59 2015 +0900
@@ -27,21 +27,30 @@
         bmknames = lambda repo: repo._bookmarks.keys()
         bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
         bmknodemap = lambda repo, name: repo.nodebookmarks(name)
-        n = namespace("bookmarks", templatename="bookmark", listnames=bmknames,
+        n = namespace("bookmarks", templatename="bookmark",
+                      # i18n: column positioning for "hg log"
+                      logfmt=_("bookmark:    %s\n"),
+                      listnames=bmknames,
                       namemap=bmknamemap, nodemap=bmknodemap)
         self.addnamespace(n)
 
         tagnames = lambda repo: [t for t, n in repo.tagslist()]
         tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
         tagnodemap = lambda repo, name: repo.nodetags(name)
-        n = namespace("tags", templatename="tag", listnames=tagnames,
+        n = namespace("tags", templatename="tag",
+                      # i18n: column positioning for "hg log"
+                      logfmt=_("tag:         %s\n"),
+                      listnames=tagnames,
                       namemap=tagnamemap, nodemap=tagnodemap)
         self.addnamespace(n)
 
         bnames = lambda repo: repo.branchmap().keys()
         bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
         bnodemap = lambda repo, node: [repo[node].branch()]
-        n = namespace("branches", templatename="branch", listnames=bnames,
+        n = namespace("branches", templatename="branch",
+                      # i18n: column positioning for "hg log"
+                      logfmt=_("branch:      %s\n"),
+                      listnames=bnames,
                       namemap=bnamemap, nodemap=bnodemap)
         self.addnamespace(n)
 
@@ -121,7 +130,7 @@
     """
 
     def __init__(self, name, templatename=None, logname=None, colorname=None,
-                 listnames=None, namemap=None, nodemap=None):
+                 logfmt=None, listnames=None, namemap=None, nodemap=None):
         """create a namespace
 
         name: the namespace to be registered (in plural form)
@@ -130,6 +139,8 @@
                  is used
         colorname: the name to use for colored log output; if not specified
                    logname is used
+        logfmt: the format to use for (l10n-ed) log output; if not specified
+                it is composed from logname
         listnames: function to list all names
         namemap: function that inputs a node, output name(s)
         nodemap: function that inputs a name, output node(s)
@@ -139,6 +150,7 @@
         self.templatename = templatename
         self.logname = logname
         self.colorname = colorname
+        self.logfmt = logfmt
         self.listnames = listnames
         self.namemap = namemap
         self.nodemap = nodemap
@@ -151,6 +163,11 @@
         if self.colorname is None:
             self.colorname = self.logname
 
+        # if logfmt is not specified, compose it from logname as backup
+        if self.logfmt is None:
+            # i18n: column positioning for "hg log"
+            self.logfmt = ("%s:" % self.logname).ljust(13) + "%s\n"
+
     def names(self, repo, node):
         """method that returns a (sorted) list of names in a namespace that
         match a given node"""