Submitter | Katsunori FUJIWARA |
---|---|
Date | Jan. 28, 2015, 1:29 p.m. |
Message ID | <3da525e1db16adbc3273.1422451786@juju> |
Download | mbox | patch |
Permalink | /patch/7570/ |
State | Accepted |
Commit | 448bb32b8ee695ab248290c6f347af0d4bc234e8 |
Headers | show |
Comments
FUJIWARA Katsunori writes: > # HG changeset patch > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > # Date 1422451379 -32400 > # Wed Jan 28 22:22:59 2015 +0900 > # Branch stable > # Node ID 3da525e1db16adbc32734aa86a20cc7254724eb3 > # Parent 1f3b94e8dc4012051482f54b51a07ff66e15dee2 > 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. > > diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py > --- a/mercurial/cmdutil.py > +++ b/mercurial/cmdutil.py > @@ -919,9 +919,8 @@ class changeset_printer(object): > # 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) Something I missed the first time around, isn't this double translating ns.logfmt? > if self.ui.debugflag: > # i18n: column positioning for "hg log" > self.ui.write(_("phase: %s\n") % _(ctx.phasestr()), > diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py > --- a/mercurial/namespaces.py > +++ b/mercurial/namespaces.py > @@ -27,21 +27,30 @@ class namespaces(object): > 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, logfmt=_("bookmark: %s\n") but above it's _(ns.logfmt)?
On Wed, 2015-01-28 at 22:29 +0900, FUJIWARA Katsunori wrote: > # HG changeset patch > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > # Date 1422451379 -32400 > # Wed Jan 28 22:22:59 2015 +0900 > # Branch stable > # Node ID 3da525e1db16adbc32734aa86a20cc7254724eb3 > # Parent 1f3b94e8dc4012051482f54b51a07ff66e15dee2 > namespace: introduce logfmt to show l10n-ed messages for hg log correctly Queued for stable (with the double-translation Sean spotted dropped), thanks!
At Wed, 28 Jan 2015 10:23:46 -0800, Sean Farley wrote: > > > FUJIWARA Katsunori writes: > > > # HG changeset patch > > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > > # Date 1422451379 -32400 > > # Wed Jan 28 22:22:59 2015 +0900 > > # Branch stable > > # Node ID 3da525e1db16adbc32734aa86a20cc7254724eb3 > > # Parent 1f3b94e8dc4012051482f54b51a07ff66e15dee2 > > 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. > > > > diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py > > --- a/mercurial/cmdutil.py > > +++ b/mercurial/cmdutil.py > > @@ -919,9 +919,8 @@ class changeset_printer(object): > > # 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) > > Something I missed the first time around, isn't this double translating > ns.logfmt? Oops, you are right ! Thank you for checking deeply ! > > if self.ui.debugflag: > > # i18n: column positioning for "hg log" > > self.ui.write(_("phase: %s\n") % _(ctx.phasestr()), > > diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py > > --- a/mercurial/namespaces.py > > +++ b/mercurial/namespaces.py > > @@ -27,21 +27,30 @@ class namespaces(object): > > 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, > > logfmt=_("bookmark: %s\n") but above it's _(ns.logfmt)? > ---------------------------------------------------------------------- [FUJIWARA Katsunori] foozy@lares.dti.ne.jp
On 28-01-2015 11:29, FUJIWARA Katsunori wrote: > # HG changeset patch > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > # Date 1422451379 -32400 > # Wed Jan 28 22:22:59 2015 +0900 > # Branch stable > # Node ID 3da525e1db16adbc32734aa86a20cc7254724eb3 > # Parent 1f3b94e8dc4012051482f54b51a07ff66e15dee2 > namespace: introduce logfmt to show l10n-ed messages for hg log correctly I just tested this on stable tip; thanks a lot! Best regards, Wagner
Patch
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -919,9 +919,8 @@ class changeset_printer(object): # 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()), diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py --- a/mercurial/namespaces.py +++ b/mercurial/namespaces.py @@ -27,21 +27,30 @@ class namespaces(object): 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 @@ class namespace(object): """ 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 @@ class namespace(object): 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 @@ class namespace(object): 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 @@ class namespace(object): 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"""