core, frontends: fix invalid translatable strings.

Some f-strings where used in translatable text, this has been fixed by using explicit
`format()` call (using a script based on `tokenize`).

As tokenize messes with spaces, a reformating tool (`black`) has been applied to some
files afterwards.
This commit is contained in:
Goffi 2021-06-14 18:35:12 +02:00
commit 7adbf3ead8

View file

@ -153,8 +153,10 @@ class LiberviaCli:
background = self.guess_background()
if background not in ('dark', 'light'):
raise exceptions.ConfigError(_(
f'Invalid value set for "background" ({background!r}), please check '
f'your settings in libervia.conf'))
'Invalid value set for "background" ({background}), please check '
'your settings in libervia.conf').format(
background=repr(background)
))
if background == 'light':
C.A_HEADER = A.FG_MAGENTA
C.A_SUBHEADER = A.BOLD + A.FG_RED
@ -449,7 +451,8 @@ class LiberviaCli:
if default:
if type_ in self.default_output:
self.disp(
_(f'there is already a default output for {type_}, ignoring new one')
_('there is already a default output for {type}, ignoring new one')
.format(type=type_)
)
else:
self.default_output[type_] = name
@ -493,7 +496,8 @@ class LiberviaCli:
self.import_plugin_module(module, type_)
except ImportError as e:
self.disp(
_(f"Can't import {module_path} plugin, ignoring it: {e}"),
_("Can't import {module_path} plugin, ignoring it: {e}")
.format(module_path=module_path, e=e),
error=True)
except exceptions.CancelError:
continue
@ -512,7 +516,10 @@ class LiberviaCli:
try:
class_names = getattr(module, '__{}__'.format(type_))
except AttributeError:
log.disp(_(f"Invalid plugin module [{type_}] {module}"), error=True)
log.disp(
_("Invalid plugin module [{type}] {module}")
.format(type=type_, module=module),
error=True)
raise ImportError
else:
for class_name in class_names:
@ -601,7 +608,9 @@ class LiberviaCli:
if not item_last:
self.args.item = uri_item
else:
self.parser.error(_(f'XMPP URL is not a pubsub one: {url}'))
self.parser.error(
_('XMPP URL is not a pubsub one: {url}').format(url=url)
)
flags = self.args._cmd._pubsub_flags
# we check required arguments here instead of using add_arguments' required option
# because the required argument can be set in URL
@ -647,13 +656,15 @@ class LiberviaCli:
await self.bridge.bridgeConnect()
except Exception as e:
if isinstance(e, exceptions.BridgeExceptionNoService):
print((_("Can't connect to SàT backend, are you sure it's launched ?")))
print(_("Can't connect to SàT backend, are you sure it's launched ?"))
self.quit(C.EXIT_BACKEND_NOT_FOUND, raise_exc=False)
elif isinstance(e, exceptions.BridgeInitError):
print((_("Can't init bridge")))
print(_("Can't init bridge"))
self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False)
else:
print((_(f"Error while initialising bridge: {e}")))
print(
_("Error while initialising bridge: {e}").format(e=e)
)
self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False)
return
self.version = await self.bridge.getVersion()
@ -844,7 +855,10 @@ class LiberviaCli:
self.profile = await self.bridge.profileNameGet(self.args.profile)
if not self.profile:
log.error(_(f"The profile [{self.args.profile}] doesn't exist"))
log.error(
_("The profile [{profile}] doesn't exist")
.format(profile=self.args.profile)
)
self.quit(C.EXIT_ERROR)
try:
@ -861,9 +875,11 @@ class LiberviaCli:
elif not await self.bridge.profileIsSessionStarted(self.profile):
if not self.args.connect:
self.disp(_(
f"Session for [{self.profile}] is not started, please start it "
f"before using jp, or use either --start-session or --connect "
f"option"), error=True)
"Session for [{profile}] is not started, please start it "
"before using jp, or use either --start-session or --connect "
"option"
.format(profile=self.profile)
), error=True)
self.quit(1)
elif not getattr(self.args, "connect", False):
return
@ -882,8 +898,10 @@ class LiberviaCli:
else:
if not await self.bridge.isConnected(self.profile):
log.error(
_(f"Profile [{self.profile}] is not connected, please connect it "
f"before using jp, or use --connect option"))
_("Profile [{profile}] is not connected, please connect it "
"before using jp, or use --connect option")
.format(profile=self.profile)
)
self.quit(1)
async def get_full_jid(self, param_jid):
@ -1158,7 +1176,7 @@ class CommandBase(object):
@param error_msg(unicode): error message as sent by bridge.progressError
"""
self.disp(_(f"Error while doing operation: {e}"), error=True)
self.disp(_("Error while doing operation: {e}").format(e=e), error=True)
def disp(self, msg, verbosity=0, error=False, end='\n'):
return self.host.disp(msg, verbosity, error, end)