Patchwork [1,of,9,STABLE?] gendoc: make commnd __doc__ and extension __doc__ as translatable

login
register
mail settings
Submitter Takumi IINO
Date May 14, 2013, 7:29 a.m.
Message ID <8fcb89ec61775279bcec.1368516550@iino-no-MacBook-Air.local>
Download mbox | patch
Permalink /patch/1623/
State Superseded
Commit 814291b5e79cb5f8e8cf0687fd306bf1fbcfb0b6
Headers show

Comments

Takumi IINO - May 14, 2013, 7:29 a.m.
# HG changeset patch
# User Takumi IINO <trot.thunder@gmail.com>
# Date 1368513072 -32400
#      Tue May 14 15:31:12 2013 +0900
# Branch stable
# Node ID 8fcb89ec61775279bcecf73cd839c29991fbab4c
# Parent  12dbdd348bb0977366200bf96cb6d2afa85faf13
gendoc: make commnd __doc__ and extension __doc__ as translatable

Before this patch, commnd __doc__ and extension __doc__ are not translatable.
But other messages, like doc of helptalbe, section headers, are translatable.

This patch makes commnd __doc__ and extension __doc__ translatable.
Martin Geisler - May 14, 2013, 10:55 a.m.
Takumi IINO <trot.thunder@gmail.com> writes:

> # HG changeset patch
> # User Takumi IINO <trot.thunder@gmail.com>
> # Date 1368513072 -32400
> #      Tue May 14 15:31:12 2013 +0900
> # Branch stable
> # Node ID 8fcb89ec61775279bcecf73cd839c29991fbab4c
> # Parent  12dbdd348bb0977366200bf96cb6d2afa85faf13
> gendoc: make commnd __doc__ and extension __doc__ as translatable
>
> Before this patch, commnd __doc__ and extension __doc__ are not translatable.
> But other messages, like doc of helptalbe, section headers, are translatable.
>
> This patch makes commnd __doc__ and extension __doc__ translatable.
>
> diff --git a/doc/gendoc.py b/doc/gendoc.py
> --- a/doc/gendoc.py
> +++ b/doc/gendoc.py
> @@ -51,7 +51,7 @@
>  
>      d['cmd'] = cmds[0]
>      d['aliases'] = cmd.split("|")[1:]
> -    d['desc'] = get_desc(attr[0].__doc__)
> +    d['desc'] = get_desc(_(attr[0].__doc__))

You should not use _(...) around anything else than literal strings. So

  translated = _("hello")

is okay, but

  msg = "hello"
  translated = _(msg)

is not okay. The reason is that _(...) is used by xgettext to find and
extract translateable strings and so the argument to _ must be a literal
string.

You should instead use the i18n.gettext function to translate something
that isn't a string at runtime. The thing you translate must then
somehow have been extracted into the message catalogs. For Mercurial,
this is done by the i18n/hggettext script which is what puts command
docstrings into the hg.pot file so that translators can work on them and
so i18n.gettext can find them later.
Takumi IINO - May 15, 2013, 6:42 a.m.
Thank you for your comment.

I understood the difference between _(...) and gettext(...).
I will fix it and resend V2.


2013/5/14 Martin Geisler <martin@geisler.net>

> Takumi IINO <trot.thunder@gmail.com> writes:
>
> > # HG changeset patch
> > # User Takumi IINO <trot.thunder@gmail.com>
> > # Date 1368513072 -32400
> > #      Tue May 14 15:31:12 2013 +0900
> > # Branch stable
> > # Node ID 8fcb89ec61775279bcecf73cd839c29991fbab4c
> > # Parent  12dbdd348bb0977366200bf96cb6d2afa85faf13
> > gendoc: make commnd __doc__ and extension __doc__ as translatable
> >
> > Before this patch, commnd __doc__ and extension __doc__ are not
> translatable.
> > But other messages, like doc of helptalbe, section headers, are
> translatable.
> >
> > This patch makes commnd __doc__ and extension __doc__ translatable.
> >
> > diff --git a/doc/gendoc.py b/doc/gendoc.py
> > --- a/doc/gendoc.py
> > +++ b/doc/gendoc.py
> > @@ -51,7 +51,7 @@
> >
> >      d['cmd'] = cmds[0]
> >      d['aliases'] = cmd.split("|")[1:]
> > -    d['desc'] = get_desc(attr[0].__doc__)
> > +    d['desc'] = get_desc(_(attr[0].__doc__))
>
> You should not use _(...) around anything else than literal strings. So
>
>   translated = _("hello")
>
> is okay, but
>
>   msg = "hello"
>   translated = _(msg)
>
> is not okay. The reason is that _(...) is used by xgettext to find and
> extract translateable strings and so the argument to _ must be a literal
> string.
>
> You should instead use the i18n.gettext function to translate something
> that isn't a string at runtime. The thing you translate must then
> somehow have been extracted into the message catalogs. For Mercurial,
> this is done by the i18n/hggettext script which is what puts command
> docstrings into the hg.pot file so that translators can work on them and
> so i18n.gettext can find them later.
>
> --
> Martin Geisler
>

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -51,7 +51,7 @@ 
 
     d['cmd'] = cmds[0]
     d['aliases'] = cmd.split("|")[1:]
-    d['desc'] = get_desc(attr[0].__doc__)
+    d['desc'] = get_desc(_(attr[0].__doc__))
     d['opts'] = list(get_opts(attr[1]))
 
     s = 'hg ' + cmds[0]
@@ -102,7 +102,7 @@ 
     for extensionname in sorted(allextensionnames()):
         mod = extensions.load(None, extensionname, None)
         ui.write(minirst.subsection(extensionname))
-        ui.write("%s\n\n" % mod.__doc__)
+        ui.write("%s\n\n" % _(mod.__doc__))
         cmdtable = getattr(mod, 'cmdtable', None)
         if cmdtable:
             ui.write(minirst.subsubsection(_('Commands')))