[PATCH 0 of 6] Support for translating docstrings

Martin Geisler mg at daimi.au.dk
Sat Aug 23 13:37:19 UTC 2008


Hello everybody!

New version of my Gettext patch series. This version extracts
docstrings from hgext and mercurial/commands.py. Unfortunately *all*
docstrings found in files under hgext are extracted, and this includes
some docstrings in helper functions too. I think the easiest solution
would be to change the helper function docstrings to comments.

Also new is making sure help.helptable can be translated -- I think
this was the final part that lacked gettext support. The total number
of strings is now 1600!

Finally, I ran the test suite and fixed some small bugs.

* Patch 1 removes some code that tried to make plural forms by
  appending 's'. Updated a test case I had missed the first time.

* Patch 2 marks some extra strings for translation. It now actually
  imports _ before using it!

* Patch 3 makes it easier to find the xx.mo files. The gettext module
  would lookup xx.mo in

    /usr/share/locale/xx/LC_MESSAGES/hg.mo

  or something like that. But that makes it annoying to test new
  translations and difficult for people who does not install to that
  location. So I changed i18n.py to use a path of . or .., relative to
  the location of i18n.py. This is the same way templater.py uses to
  find the templates directory.

* Patch 4 adds new targets to the Makefile for updating the hg.pot (PO
  template) file and to generate xx.mo files. I don't particularly
  like the update-mo target name I chose -- maybe someone can come up
  with something better.

  This now uses the Gettext program msgcat to combine two pot files.

* Patch 5 restructures the helptable so that the header can be
  translated nicely in the next patch.

* Patch 6 marks strings in helptable for translation and runs
  extension docstrings through gettext. The gettext() function is used
  instead of the usual _() function since pygettext.py pays no
  attention to gettext() (but the two names denote the same function
  at runtime).

I have split off the big hg.pot and da.po patches. I think many
projects put the .pot file under revision control, but I'm not sure
why since it is auto-generated.

Anyway, please give it a try and let me know what you think! You can
create a new language by going to the po directory and running

  msginit -l xx

or simply copy the hg.pot file to xx.po where xx is your language code
(not country code: da vs dk). Then edit away and run

  make update-mo

from the root to compile the .po file into a .mo file. Then set
LANG=xx and run hg.


More information about the Mercurial-devel mailing list