Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Building translators is good clean fun. -- T. Cheatham


devel / comp.lang.python / Re: GNU gettext: Print string translated and untranslated at the same time

SubjectAuthor
o Re: GNU gettext: Print string translated and untranslated at the sameMirko

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

<mailman.236.1692289180.23016.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23891&group=comp.lang.python#23891

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: mirkok.l...@googlemail.com (Mirko)
Newsgroups: comp.lang.python
Subject: Re: GNU gettext: Print string translated and untranslated at the same
time
Date: Thu, 17 Aug 2023 18:19:35 +0200
Lines: 32
Message-ID: <mailman.236.1692289180.23016.python-list@python.org>
References: <2ecc54498066930d20ada6343bf4374d@posteo.de>
<57971807-ed3a-9e79-28d5-f37a45409dd0@googlemail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de UBG+cMbAc94PtU2M1xA9/w/GwXLYFh83IykYB9dlWMVA==
Cancel-Lock: sha1:6m931g+Xiz8FmKfeclG3FY1fUvk= sha256:0HLjqxjNGDqhTJH5ZhIFBsw+ykjIRev3XknRgRiEF5w=
Return-Path: <mirkok.lists@googlemail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=googlemail.com header.i=@googlemail.com header.b=Ed49DHqK;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.013
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'variable':
0.05; 'string': 0.07; 'from:addr:googlemail.com': 0.09; 'locally':
0.09; 'message-id:@googlemail.com': 0.09; 'originally': 0.09;
'schrieb': 0.09; 'approach.': 0.16; 'solved': 0.16; 'subject:GNU':
0.16; 'subject:string': 0.16; 'url:faq': 0.16; 'url:programming':
0.16; 'solve': 0.19; 'to:addr:python-list': 0.20; 'seems': 0.26;
'local': 0.27; 'header:User-Agent:1': 0.30; 'question': 0.32;
'there': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'following': 0.35; 'could': 0.38;
'this,': 0.39; 'try': 0.40; 'skip:o 20': 0.63; 'skip:b 10': 0.63;
'translated': 0.69; 'global': 0.73; 'received:37': 0.78;
'referenced': 0.84; 'skip:" 40': 0.84; 'so:': 0.84; 'subject: \n
': 0.84; 'me:': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20221208; t=1692289179; x=1692893979;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id:from
:to:cc:subject:date:message-id:reply-to;
bh=CgUKotxBQIZNt9dxn4SDj2/FJVLEOC6pbaoOgU3dDU0=;
b=Ed49DHqK3FEorWYpM8vU2Pi/RtC2gdv3swNz/Rnz7PoHLI3Z+pJO3jEzdDk2UQqyf2
4Xd9D2qSqu/F1ayiHYqXfK9FIe2A+WD7txb2pQcu3GJFoGITf648+07t/qbHZP8W6gOa
9ld1xNvL3JgT14Zy3dtT5bkIlY7/ieyoru5sTtgpuX2vDEk618OD4lQ7w+/9Xtu9Doiw
/nkyPdv1ShgzOrSEOaRDZZJZnsRs3DcR5AVSFjiK0JP+N8/3eCiFWjJu7R9KN8WQN1WE
KqkitYS490wZPOZvkshrC3uAJC8zRk6pJPtnt5zyOMRFfOQ0wu95jZPfhnCJiTwrLq+D
wHtQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1692289179; x=1692893979;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=CgUKotxBQIZNt9dxn4SDj2/FJVLEOC6pbaoOgU3dDU0=;
b=YWnGOw506M60Oz93FeENL5LVZ3QR9FWEIS0yXaKZ3jSgTF8LAvN+E0N7scPcb+qTWm
aQ6dQEVNL+Y58/gS1d1H2oUWY8UVjBOhSFbaZJ/PJ0yk1lzOSKENjpmX1Ll/4wqTycRk
701NOcpPZb+Nk1cHLnwGjOw6yemwMssedOXxXIUTXygWgflfIrCfS0gabwht/7nhJaGP
LYUxhWvLFh1XaHr+KCvM8s3z0k9FCEzNcgIGOK21irQI8y7f7m80gAT9Fw6/b5ZNL3BW
cVcm7R7N/bmH/xPwQaVyJ14O9PgumFNzji9hy3tGQptZX0MAzOy3hlPj30p/ipRI+VPm
zIxw==
X-Gm-Message-State: AOJu0YzOiy79HRZTgqFW9lwxLXyKVq8wCnLwXioqOUNBkWGDIoCJANM8
XQjPI1/jFGdKdpwacKJ+i4RB0D5+kUU=
X-Google-Smtp-Source: AGHT+IGW+49dl3tWX80yPJywOsxqXutw8jiBuViZdvmTtbwkZTsfoR2l4FZt2wEyCS/nxV1ljFSQ9A==
X-Received: by 2002:ac2:4d90:0:b0:4fb:a0f1:f8b8 with SMTP id
g16-20020ac24d90000000b004fba0f1f8b8mr3972460lfe.63.1692289178594;
Thu, 17 Aug 2023 09:19:38 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: de-DE
In-Reply-To: <2ecc54498066930d20ada6343bf4374d@posteo.de>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <57971807-ed3a-9e79-28d5-f37a45409dd0@googlemail.com>
X-Mailman-Original-References: <2ecc54498066930d20ada6343bf4374d@posteo.de>
 by: Mirko - Thu, 17 Aug 2023 16:19 UTC

Am 17.08.23 um 09:10 schrieb c.buhtz--- via Python-list:

>     UnboundLocalError: local variable '_' referenced before assignment

This is a common gotcha:

https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value

You could solve it by defining _() locally like so:

def foobar(translate):
_ = gettext.gettext
if not translate:
# I try to mask the global _() builtins-function
def _(txt):
return txt
return _('minutes')

> The question is if this can be solved somehow or if there is an alternative approach.

However, you might not need this, because the following seems to
work for me:

def orig_and_trans(msg):
return (_(msg), msg)

print('The translated string "{}" is originally
"{}".'.format(*orig_and_trans("hello")))

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor