[RFC][PATCH] minimal i18n support: default _() pass-through function; 'make pot' will create PO template

Lukáš Lalinský lalinsky at gmail.com
Tue May 8 21:20:11 BST 2007

On Ut, 2007-05-08 at 22:55 +0300, Alexander Belchenko wrote:
> I'm not completely understand this point.
> We are working with Python, not with C.
> There is no static strings in Python.

By "static strings" I mean strings created at import time. Anything on
module or class level will be called when importing the module.

> We may talk only about translated messages and original untranslated messages.
> Python documentation for gettext module recommends to use such approach
> when access to untranslated strings:
> http://docs.python.org/lib/node742.html
> In second example you can see mentioned N_() approach. So for clarity
> reason we can use N_() when it needed. But only one case when I think we
> need access to untranslated strings is smart sever.
> We can manipulate with _() in runtime as we need.
> And what is more, in Python both expressions _('foo') and N_('foo')
> will calling some function (named _ and N_ respectively) with string argument.
> If we return to my patch, I think all UI messages shoud use _(),
> and only in special cases (like with smart server) we can use N_().

No, this is not the point. Let's use _basic_help from bzrlib.help_topics
as an example. If you import bzrlib.help_topics, it would call _() on
the string and assign it to _basic_help. But at this time the code
doesn't know which locale to use, and can't translate the string

N_() is used only to let xgettext/pygettext know that the strings should
be included in the .pot file. _() is used to actually translate the
string, once you initialize gettext, load the correct .mo file and
install the _() function.

So in the _basic_help case, it should be something like:

class HelpTopicRegistry(registry.Registry):


    def get_detail(self, topic):
        """Get the detailed help on a given topic."""
        obj = self.get(topic)
        if callable(obj):
            obj = obj(topic)
        return _(obj)

    def get_summary(self, topic):
        """Get the single line summary for the topic."""
        return _(self.get_info(topic))


_basic_help = N_(
"""Bazaar -- a free distributed version-control tool

Basic commands:
  bzr init           makes this directory a versioned branch


topic_registry.register('basic', _basic_help, N_("Basic commands"))

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Toto je =?ISO-8859-1?Q?digit=E1lne?=
	=?ISO-8859-1?Q?_podp=EDsan=E1?= =?UTF-8?Q?_=C4=8Das=C5=A5?=
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20070508/2ceda868/attachment.pgp 

More information about the bazaar mailing list