GNU gettext: Print string translated and untranslated at the same time

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Aug 18 02:14:44 EDT 2023


On 17/08/23 7:10 pm, c.buhtz at posteo.jp wrote:
> def foobar(translate):
>     if not translate:
>         # I try to mask the global _() builtins-function
>         def _(txt):
>             return txt
>>     return _('Hello')

This causes _ to become a local that is left undefined on one
branch of the if. You need to ensure it's always defined. Here's
one way that should work:
gttran = _
def foobar(translate):
 def _(txt):
 if translate:
 return gttran(txt)
 else:
 return txt
 return _('Hello')
-- 
Greg


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /