On Monday, July 18, 2011 01:26:15 pm León Domingo wrote:
> Hi,
> I'm writing an script inside my TG2 app which I want to run in the
> terminal and I'm not able to access the ugettext or lazy_ugettext
> functions.
>
> from pylons.i18n import ugettext as _, lazy_ugettext as l_
>
> I'm getting this error
>
> TypeError: No object (name: translator) has been registered for this
> thread
You need to register the translator for the given thread. This is from some of
our code that works:
import pylons
from pylons.i18n.translation import _get_translator
# this is a hook that is needed to set up some
# things that are needed inside transaction hooks
@contextmanager
def set_language_context_manager(language=None, **kwargs):
# this is stolen from the pylons test setup.
# it will make sure the gettext-stuff is working
translator = _get_translator(language, **kwargs)
pylons.translator._push_object(translator)
try:
yield
finally:
pylons.translator._pop_object()
HTH,
Diez
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.