[Merge] lp:~songofacandy/bzr/i18n into lp:bzr
Alexander Belchenko
bialix at ukr.net
Thu May 12 09:23:09 UTC 2011
David Planella пишет:
> El dc 11 de 05 de 2011 a les 14:24 +0300, en/na Alexander Belchenko va
> escriure:
>> Alexander Belchenko пишет:
>>> Vincent Ladeuil пишет:
>>>> <snip/>
>>>>
>>>> > Because _ has special meaning in PDB. Why does it matter?
>> I can add even more reasons against using _() in first place.
>>
>> Function _() is just alias to some gettext method which is bound to
>> specific language at installing time.
>>
>> So the usual practice for GUI applications is to install _() into global
>> namespace leaving gettext to determine what language user wants to see
>> and don't care about translations anymore.
>>
>
> Not arguing in favour of any approach here, just a quick note here to
> mention that most of the translatable Python apps out there don't use
> gettext.install() to install _() into global namespace.
>
> They rather use something along the lines of:
>
> import gettext
> gettext.bindtextdomain('myapplication', '/path/to/my/language/directory')
> gettext.textdomain('myapplication')
> _ = gettext.gettext
>
> # ...
> print _('This is a translatable string.')
>
> (Example from the Python gettext docs)
>
> Additionally you can call setlocale to explicitly set the default system
> locale.
OK, definitely there are 2 ways to use python gettext, and both of them
explained in the python documentation:
1) Using GNU gettext like API:
http://docs.python.org/library/gettext.html?highlight=gettext#gnu-gettext-api
That API forces using only functions, like in you example above.
2) Using Class-based python-style API:
http://docs.python.org/library/gettext.html?highlight=gettext#class-based-api
That API is more pythonic and maybe sometimes simpler, and in fact
current implementation of GNU gettext-like API is built on top of
class-based API.
In QBzr/Explorer we're using class-based API and for GUI it works OK.
I'm not sure though what's the right way for CLI bzr here.
As I can tell GNU gettext like API can change the language on-the-fly
following environment variables 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES',
'LANG'. While with class-based API user code should care about that
manually.
More information about the bazaar
mailing list