[RFC][PATCH] minimal i18n support: default _() pass-through function; 'make pot' will create PO template
Alexander Belchenko
bialix at ukr.net
Tue May 8 21:38:12 BST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Lukáš Lalinský пишет:
> 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
> correctly.
>
> 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
> http://bazaar-vcs.org/
>
> Basic commands:
> bzr init makes this directory a versioned branch
> ...
> """)
>
> ...
>
> topic_registry.register('basic', _basic_help, N_("Basic commands"))
>
Thank you for detailed clarification.
I need to think over.
[µ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGQN+0zYr338mxwCURAvY0AJ9fZpDUsVH2CaLrc0ovEX/NwZlJ+wCfT+79
hV/88N0NHI4NqaP/Quey5Kg=
=ZWS8
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list