From b0e2e893951d98b88dac5c34d39d49e90dac1c88 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 10 Jan 2023 14:06:29 +0000 Subject: [PATCH] i18n: document not to use old-style (%) string formatting --- electrum/i18n.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/electrum/i18n.py b/electrum/i18n.py index 15310b614..a98ea1d39 100644 --- a/electrum/i18n.py +++ b/electrum/i18n.py @@ -30,6 +30,11 @@ LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') language = gettext.translation('electrum', LOCALE_DIR, fallback=True) +# note: do not use old-style (%) formatting inside translations, +# as syntactically incorrectly translated strings would raise exceptions (see #3237). +# e.g. consider _("Connected to %d nodes.") % n +# >>> "Connecté aux noeuds" % n +# TypeError: not all arguments converted during string formatting # note: f-strings cannot be translated! see https://stackoverflow.com/q/49797658 # So this does not work: _(f"My name: {name}") # instead use .format: _("My name: {}").format(name)