From 946c5a493f53c517b90e58a18f1cffa5694093b7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 Feb 2019 06:27:36 -0500 Subject: [PATCH] [services-*] Fix translations - Strings like "{} the {} with {}" are terrible for translators: - no context - no possibility to re-order grammatical units - substituting in English parts-of-speech is going to make a mess - Write the strings out with explicitly named substitutions, no part-of-speech substitution, and better formatting. --- src/modules/services-openrc/main.py | 37 +++++++++++++++++++++++----- src/modules/services-systemd/main.py | 20 +++++++++++++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/modules/services-openrc/main.py b/src/modules/services-openrc/main.py index 46890dd98..23591fb84 100644 --- a/src/modules/services-openrc/main.py +++ b/src/modules/services-openrc/main.py @@ -56,6 +56,22 @@ class OpenrcController: self.initdDir = libcalamares.job.configuration['initdDir'] self.runlevelsDir = libcalamares.job.configuration['runlevelsDir'] + + def make_failure_description(self, state, name, runlevel): + """ + Returns a generic "could not " failure message, specialized + for the action @p state and the specific service @p name in @p runlevel. + """ + if state == "add": + description = _("Cannot add service {name!s} to run-level {level!s}.") + elif state == "del": + description = _("Cannot remove service {name!s} from run-level {level!s}.") + else: + description = _("Unknown service-action {arg!s} for service {name!s} in run-level {level!s}.") + + return description.format(arg=state, name=name, level=runlevel) + + def update(self, state): """ Call rc-update for each service listed @@ -83,19 +99,28 @@ class OpenrcController: warning("Cannot {} service {} to {}".format(state, name, runlevel)) warning("rc-update returned error code {!s}".format(ec)) if mandatory: - return (_("Cannot {} service {} to {}").format(state, name, runlevel), - _("rc-update {} call in chroot returned error code {}").format(state, ec) + title = _("Cannot modify service") + diagnostic = _("rc-update {arg!s} call in chroot returned error code {num!s}.").format(arg=state, num=ec) + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic ) else: warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) if mandatory: - return (_("Target runlevel {} does not exist for {}.").format(runlevel, name), - _("No {} found.").format(runlevel_path)) + title = _("Target runlevel does not exist") + diagnostic = _("The path for runlevel {level!s} is {path!s}, which does not exist.").format(level=runlevel, path=runlevel_path) + + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic + ) else: warning("Target service {} does not exist in {}.".format(name, self.initdDir)) if mandatory: - return (_("Target service {} does not exist.").format(name), - _("No {} found.").format(service_path)) + title = _("Target service does not exist") + diagnostic = _("The path for service {name!s} is {path!s}, which does not exist.").format(name=name, path=service_path) + return (title, + self.make_failure_description(state, name, runlevel) + " " + diagnostic + ) def run(self): diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py index 1cb5899ae..cd13d9ce9 100644 --- a/src/modules/services-systemd/main.py +++ b/src/modules/services-systemd/main.py @@ -65,8 +65,24 @@ def systemctl(targets, command, suffix): "systemctl {} call in chroot returned error code {}".format(command, ec) ) if mandatory: - return (_("Cannot {} systemd {} {}").format(command, suffix, name), - _("systemctl {} call in chroot returned error code {}").format(command, ec) + title = _("Cannot modify service") + diagnostic = _("systemctl {arg!s} call in chroot returned error code {num!s}.").format(arg=command, num=ec) + + if command == "enable" and suffix == ".service": + description = _("Cannot enable systemd service {name!s}.") + elif command == "enable" and suffix == ".target": + description = _("Cannot enable systemd target {name!s}.") + elif command == "disable" and suffix == ".service": + description = _("Cannot enable systemd service {name!s}.") + elif command == "disable" and suffix == ".target": + description = _("Cannot disable systemd target {name!s}.") + elif command == "mask": + description = _("Cannot mask systemd unit {name!s}.") + else: + description = _("Unknown systemd commands {command!s} and {suffix!s} for unit {name!s}.") + + return (title, + description.format(name=name, command=command, suffix=suffix) + " " + diagnostic ) return None