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

@ -53,20 +53,19 @@ class Method(base.CommandBase, BridgeCommon):
self.parser.add_argument(
"method", type=str, help=_("name of the method to execute")
)
self.parser.add_argument(
"arg", nargs="*", help=_("argument of the method")
)
self.parser.add_argument("arg", nargs="*", help=_("argument of the method"))
async def start(self):
method = getattr(self.host.bridge, self.args.method)
import inspect
argspec = inspect.getargspec(method)
kwargs = {}
if 'profile_key' in argspec.args:
kwargs['profile_key'] = self.profile
elif 'profile' in argspec.args:
kwargs['profile'] = self.profile
if "profile_key" in argspec.args:
kwargs["profile_key"] = self.profile
elif "profile" in argspec.args:
kwargs["profile"] = self.profile
args = self.evalArgs()
@ -76,7 +75,12 @@ class Method(base.CommandBase, BridgeCommon):
**kwargs,
)
except Exception as e:
self.disp(_(f"Error while executing {self.args.method}: {e}"), error=True)
self.disp(
_("Error while executing {method}: {e}").format(
method=self.args.method, e=e
),
error=True,
)
self.host.quit(C.EXIT_ERROR)
else:
if ret is not None:
@ -92,12 +96,8 @@ class Signal(base.CommandBase, BridgeCommon):
BridgeCommon.__init__(self)
def add_parser_options(self):
self.parser.add_argument(
"signal", type=str, help=_("name of the signal to send")
)
self.parser.add_argument(
"arg", nargs="*", help=_("argument of the signal")
)
self.parser.add_argument("signal", type=str, help=_("name of the signal to send"))
self.parser.add_argument("arg", nargs="*", help=_("argument of the signal"))
async def start(self):
args = self.evalArgs()
@ -105,9 +105,11 @@ class Signal(base.CommandBase, BridgeCommon):
# XXX: we use self.args.profile and not self.profile
# because we want the raw profile_key (so plugin handle C.PROF_KEY_NONE)
try:
await self.host.bridge.debugFakeSignal(self.args.signal, json_args, self.args.profile)
await self.host.bridge.debugFakeSignal(
self.args.signal, json_args, self.args.profile
)
except Exception as e:
self.disp(_(f"Can't send fake signal: {e}"), error=True)
self.disp(_("Can't send fake signal: {e}").format(e=e), error=True)
self.host.quit(C.EXIT_ERROR)
else:
self.host.quit()
@ -198,18 +200,17 @@ class Theme(base.CommandBase):
async def start(self):
for attr in dir(C):
if not attr.startswith('A_'):
if not attr.startswith("A_"):
continue
color = getattr(C, attr)
if attr == 'A_LEVEL_COLORS':
if attr == "A_LEVEL_COLORS":
# This constant contains multiple colors
self.disp('LEVEL COLORS: ', end=' ')
self.disp("LEVEL COLORS: ", end=" ")
for idx, c in enumerate(color):
last = idx == len(color)-1
end = '\n' if last else ' '
last = idx == len(color) - 1
end = "\n" if last else " "
self.disp(
c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''),
end=end
c + f"LEVEL_{idx}" + A.RESET + (", " if not last else ""), end=end
)
else:
text = attr[2:]