Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Those who can, do; those who can't, write. Those who can't write work for the Bell Labs Record.


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 sameBarry

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

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

  copy mid

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

  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: bar...@barrys-emacs.org (Barry)
Newsgroups: comp.lang.python
Subject: Re: GNU gettext: Print string translated and untranslated at the same
time
Date: Fri, 18 Aug 2023 07:59:06 +0100
Lines: 33
Message-ID: <mailman.242.1692341965.23016.python-list@python.org>
References: <2ecc54498066930d20ada6343bf4374d@posteo.de>
<B5F12F32-020A-4D6F-B3A5-D7757622E6BE@barrys-emacs.org>
Mime-Version: 1.0 (1.0)
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 5RTaEx/9WAKCzJZ3RgYREwPAgMSu3RbM+9QrEtWckWWw==
Cancel-Lock: sha1:Mrd08I2y6qQOjoCjNIfdQ21VQwI= sha256:7jdjZ0JDWJt8+zbviWbBDp+q2QuTAK6OCHgcK1A8oi4=
Return-Path: <barry@barrys-emacs.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'aug': 0.07;
'string': 0.07; 'code?': 0.09; 'from:addr:barry': 0.09; 'parse':
0.09; 'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09;
'solving': 0.09; 'cc:no real name:2**0': 0.14; 'barry': 0.16;
'from:addr:barrys-emacs.org': 0.16; 'message-id:@barrys-
emacs.org': 0.16; 'parsing': 0.16; 'subject:GNU': 0.16;
'subject:string': 0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr
:python-list': 0.20; 'version': 0.23; 'cc:2**0': 0.25; 'email
addr:python.org&gt;': 0.28; 'python-list': 0.32; "wouldn't": 0.32;
'header:In-Reply-To:1': 0.34; 'display': 0.36; 'source': 0.36;
'file': 0.38; 'use': 0.39; 'want': 0.40; 'tell': 0.60; 'key':
0.64; 'etc,': 0.69; 'translated': 0.69; 'site': 0.70; 'deal':
0.73; 'covered': 0.75; 'email name:&lt;python-list': 0.84;
'strings': 0.84; 'word.': 0.91
In-Reply-To: <2ecc54498066930d20ada6343bf4374d@posteo.de>
X-Mailer: iPad Mail (20G75)
X-GND-Sasl: barry@barrys-emacs.org
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <B5F12F32-020A-4D6F-B3A5-D7757622E6BE@barrys-emacs.org>
X-Mailman-Original-References: <2ecc54498066930d20ada6343bf4374d@posteo.de>
 by: Barry - Fri, 18 Aug 2023 06:59 UTC

> On 17 Aug 2023, at 15:01, c.buhtz--- via Python-list <python-list@python.org> wrote:
>
> I want to display one string in its original source (untranslated) version and in its translated version site by site without duplicating the string in the python source code?
> It wouldn't be a big deal if it is only one word.

The key to solving this to separate the parsing of the string into the .po file and its translation.

def i18n(s):
return s

msg = i18n(‘my message’)

print(_(msg))
print(msg)

Now you tell the xgettex, pygettext etc, to parse to use “i18n” to find strings to translate.

This is covered in the docs at https://docs.python.org/3/library/gettext.html#localizing-your-module

Barry

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor