GNU gettext: Print string translated and untranslated at the same time
Mirko
mirkok.lists at googlemail.com
Thu Aug 17 17:30:09 EDT 2023
Am 17.08.23 um 21:17 schrieb c.buhtz--- via Python-list:
> Hello Mirko,
>
> thanks for reply.
>
> Am 17.08.2023 18:19 schrieb Mirko via Python-list:
>> You could solve it by defining _() locally like so:
>>
>> def foobar(translate):
>> _ = gettext.gettext
>
> I see no way to do that. It is not the "class based API" of gettext
> installing _() into the builtins namespace.
Does this work:
def foobar(translate):
_ = __builtins__._
> My users are able to configure the language of their UI explicit. It
> is a full application.
>
>> def orig_and_trans(msg):
>> return (_(msg), msg)
>
> This will be ignored by GNU gettext utils (xgettext in my case) will
> ignore this line because they do not know what "msg" is. The string
> "hello" won't appear in the pot-file.
xgettext has an option "-k" which allows you to specify an
additional "keyword" (like a function name, I guess) for detecting
translatable strings. With the orig_and_trans() function, the
following command produces a messages.po with "hello" in it.
xgettext -korig_and_trans source.py
More information about the Python-list
mailing list