comparison mercurial/namespaces.py @ 23967:448bb32b8ee6 stable

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 28 Jan 2015 22:22:59 +0900
parents e573dd08aeaf
children 38824c53c2f1
comparison
equal deleted inserted replaced
23966:2d2c0a8eeeb8 23967:448bb32b8ee6
25 # we need current mercurial named objects (bookmarks, tags, and 25 # we need current mercurial named objects (bookmarks, tags, and
26 # branches) to be initialized somewhere, so that place is here 26 # branches) to be initialized somewhere, so that place is here
27 bmknames = lambda repo: repo._bookmarks.keys() 27 bmknames = lambda repo: repo._bookmarks.keys()
28 bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name)) 28 bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
29 bmknodemap = lambda repo, name: repo.nodebookmarks(name) 29 bmknodemap = lambda repo, name: repo.nodebookmarks(name)
30 n = namespace("bookmarks", templatename="bookmark", listnames=bmknames, 30 n = namespace("bookmarks", templatename="bookmark",
31 # i18n: column positioning for "hg log"
32 logfmt=_("bookmark: %s\n"),
33 listnames=bmknames,
31 namemap=bmknamemap, nodemap=bmknodemap) 34 namemap=bmknamemap, nodemap=bmknodemap)
32 self.addnamespace(n) 35 self.addnamespace(n)
33 36
34 tagnames = lambda repo: [t for t, n in repo.tagslist()] 37 tagnames = lambda repo: [t for t, n in repo.tagslist()]
35 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) 38 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
36 tagnodemap = lambda repo, name: repo.nodetags(name) 39 tagnodemap = lambda repo, name: repo.nodetags(name)
37 n = namespace("tags", templatename="tag", listnames=tagnames, 40 n = namespace("tags", templatename="tag",
41 # i18n: column positioning for "hg log"
42 logfmt=_("tag: %s\n"),
43 listnames=tagnames,
38 namemap=tagnamemap, nodemap=tagnodemap) 44 namemap=tagnamemap, nodemap=tagnodemap)
39 self.addnamespace(n) 45 self.addnamespace(n)
40 46
41 bnames = lambda repo: repo.branchmap().keys() 47 bnames = lambda repo: repo.branchmap().keys()
42 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) 48 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
43 bnodemap = lambda repo, node: [repo[node].branch()] 49 bnodemap = lambda repo, node: [repo[node].branch()]
44 n = namespace("branches", templatename="branch", listnames=bnames, 50 n = namespace("branches", templatename="branch",
51 # i18n: column positioning for "hg log"
52 logfmt=_("branch: %s\n"),
53 listnames=bnames,
45 namemap=bnamemap, nodemap=bnodemap) 54 namemap=bnamemap, nodemap=bnodemap)
46 self.addnamespace(n) 55 self.addnamespace(n)
47 56
48 def __getitem__(self, namespace): 57 def __getitem__(self, namespace):
49 """returns the namespace object""" 58 """returns the namespace object"""
119 'nodemap': function that takes a node and returns a list of names 128 'nodemap': function that takes a node and returns a list of names
120 129
121 """ 130 """
122 131
123 def __init__(self, name, templatename=None, logname=None, colorname=None, 132 def __init__(self, name, templatename=None, logname=None, colorname=None,
124 listnames=None, namemap=None, nodemap=None): 133 logfmt=None, listnames=None, namemap=None, nodemap=None):
125 """create a namespace 134 """create a namespace
126 135
127 name: the namespace to be registered (in plural form) 136 name: the namespace to be registered (in plural form)
128 templatename: the name to use for templating 137 templatename: the name to use for templating
129 logname: the name to use for log output; if not specified templatename 138 logname: the name to use for log output; if not specified templatename
130 is used 139 is used
131 colorname: the name to use for colored log output; if not specified 140 colorname: the name to use for colored log output; if not specified
132 logname is used 141 logname is used
142 logfmt: the format to use for (l10n-ed) log output; if not specified
143 it is composed from logname
133 listnames: function to list all names 144 listnames: function to list all names
134 namemap: function that inputs a node, output name(s) 145 namemap: function that inputs a node, output name(s)
135 nodemap: function that inputs a name, output node(s) 146 nodemap: function that inputs a name, output node(s)
136 147
137 """ 148 """
138 self.name = name 149 self.name = name
139 self.templatename = templatename 150 self.templatename = templatename
140 self.logname = logname 151 self.logname = logname
141 self.colorname = colorname 152 self.colorname = colorname
153 self.logfmt = logfmt
142 self.listnames = listnames 154 self.listnames = listnames
143 self.namemap = namemap 155 self.namemap = namemap
144 self.nodemap = nodemap 156 self.nodemap = nodemap
145 157
146 # if logname is not specified, use the template name as backup 158 # if logname is not specified, use the template name as backup
149 161
150 # if colorname is not specified, just use the logname as a backup 162 # if colorname is not specified, just use the logname as a backup
151 if self.colorname is None: 163 if self.colorname is None:
152 self.colorname = self.logname 164 self.colorname = self.logname
153 165
166 # if logfmt is not specified, compose it from logname as backup
167 if self.logfmt is None:
168 # i18n: column positioning for "hg log"
169 self.logfmt = ("%s:" % self.logname).ljust(13) + "%s\n"
170
154 def names(self, repo, node): 171 def names(self, repo, node):
155 """method that returns a (sorted) list of names in a namespace that 172 """method that returns a (sorted) list of names in a namespace that
156 match a given node""" 173 match a given node"""
157 return sorted(self.nodemap(repo, node)) 174 return sorted(self.nodemap(repo, node))
158 175