Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Science is what happens when preconception meets verification.


devel / comp.lang.python / Re: f-strings and internationalisation.

SubjectAuthor
o Re: f-strings and internationalisation.Barry Scott

1
Re: f-strings and internationalisation.

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: bar...@barrys-emacs.org (Barry Scott)
Newsgroups: comp.lang.python
Subject: Re: f-strings and internationalisation.
Date: Mon, 24 May 2021 20:14:07 +0100
Lines: 45
Message-ID: <mailman.313.1621883656.3087.python-list@python.org>
References: <0f9f1d78-4edd-af6f-82bb-4dba96c59326@rece.vub.ac.be>
<F7B68971-EAB2-4A4B-86CA-84C7ED6FEB19@barrys-emacs.org>
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.80.0.2.43\))
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de ixqsqWHobwRG8J2lPJJYpAaxZPu+l0HIo5yEv9fHL9zQ==
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.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.05;
'url:mailman': 0.09; 'barry': 0.09; 'cc:addr:python-list': 0.09;
'from:addr:barry': 0.09; 'received:217.70': 0.09;
'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09;
'url:2015': 0.09; 'looks': 0.11; 'cc:no real name:2**0': 0.13;
'antoon': 0.16; 'for.': 0.16; 'from:addr:barrys-emacs.org': 0.16;
'from:name:barry scott': 0.16; 'i18n': 0.16; 'languages.': 0.16;
'message-id:@barrys-emacs.org': 0.16; 'pardon': 0.16; 'pardon.':
0.16; 'skip:{ 30': 0.16; 'swap': 0.16; 'translation.': 0.16;
'wrote:': 0.16; 'url:listinfo': 0.16; 'cc:addr:python.org': 0.19;
'url-ip:188.166.95.178/32': 0.20; 'url-ip:188.166.95/24': 0.20;
'url-ip:188.166/16': 0.23; 'cannot': 0.24; 'thinking': 0.26;
'seems': 0.26; 'cc:2**0': 0.27; 'done': 0.28; 'url-ip:188/8':
0.29; 'header:In-Reply-To:1': 0.33; 'url:blog': 0.37; 'author':
0.38; 'use': 0.38; 'url-ip:151.101.36.223/32': 0.38; 'url-
ip:151.101.36/24': 0.38; 'does': 0.38; 'english': 0.61; 'forward':
0.61; 'well.': 0.61; 'url-ip:3/8': 0.63; 'your': 0.64; 'authors':
0.65; 'above': 0.65; 'parts': 0.66; 'received:217': 0.68; 'free':
0.68; 'order': 0.68; 'tools': 0.75; 'details.': 0.77; 'drastic':
0.84; 'subject:skip:i 20': 0.84; 'url-ip:138.197/16': 0.84; 'url-
ip:138/8': 0.84; 'occasion': 0.91
In-Reply-To: <0f9f1d78-4edd-af6f-82bb-4dba96c59326@rece.vub.ac.be>
X-Mailer: Apple Mail (2.3654.80.0.2.43)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <F7B68971-EAB2-4A4B-86CA-84C7ED6FEB19@barrys-emacs.org>
X-Mailman-Original-References: <0f9f1d78-4edd-af6f-82bb-4dba96c59326@rece.vub.ac.be>
 by: Barry Scott - Mon, 24 May 2021 19:14 UTC

> On 24 May 2021, at 19:30, Antoon Pardon <antoon.pardon@rece.vub.ac.be> wrote:
>
> I have now come across several occasion where an author advice the use
> of f-strings above the %-formatting and the format method. However it
> seems these authors were only thinking about rather straight forward
> english communication.
>
> So what if you want your application to work with multiple languages.
> Can that be done with f-strings?

No it cannot be done. This is because a translation can reorder
the parts of the string is drastic ways that f'strings' does not allow for.

You need to use this style:

_('This %(arg1)s and %(arg2)s') % {'arg1': value_arg1, 'arg2': value_arg2}

or
_('This {arg1} and {arg2}').format(arg1=value_args, arg2=values_arg2)

A translator would be free to swap arg1 and arg2 order in a translation.

See https://docs.python.org/3/library/gettext.html for more details.
And https://www.mattlayman.com/blog/2015/i18n/ looks useful as well.

Then you can use use the I18N gettext tools to make a .pot and .po files.

Barry

>
> --
> Antoon Pardon.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor