bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.44k stars 1.47k forks source link

Can't access the gettext function "_()" in simpleTemplate #486

Open visig9 opened 11 years ago

visig9 commented 11 years ago

Look Here:

% import gettext
% gettext.install('ProgramX') # It will set _ = gettext.gettext in python builtins namespace.

...

{{!_('Translate Me!')}} % # But it failed! _ be occupied by a dict object and it not callable...

How could I access the gettext interface "_"?

The _.get('__builtins__').get('_')('Translated Me') really not a good idea... (because xgettext program are hard to parse and extract the string which need to be translated, and of course, it too long!)

Thanks!

About gettext.install(): http://docs.python.org/3.3/library/gettext.html#gettext.install

iurisilvio commented 11 years ago

Yes, SimpleTemplate set a _ variable, which probably override your _.

https://github.com/defnull/bottle/blob/master/bottle.py#L3143

I'm sure it can be changed to not conflict with the underscore used by gettext.