[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.
This commit is contained in:
Adriaan de Groot 2019-02-18 06:27:36 -05:00
parent 879c5e3cee
commit 946c5a493f
2 changed files with 49 additions and 8 deletions

View File

@ -56,6 +56,22 @@ class OpenrcController:
self.initdDir = libcalamares.job.configuration['initdDir'] self.initdDir = libcalamares.job.configuration['initdDir']
self.runlevelsDir = libcalamares.job.configuration['runlevelsDir'] self.runlevelsDir = libcalamares.job.configuration['runlevelsDir']
def make_failure_description(self, state, name, runlevel):
"""
Returns a generic "could not <foo>" 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 <code>{arg!s}</code> for service {name!s} in run-level {level!s}.")
return description.format(arg=state, name=name, level=runlevel)
def update(self, state): def update(self, state):
""" """
Call rc-update for each service listed Call rc-update for each service listed
@ -83,19 +99,28 @@ class OpenrcController:
warning("Cannot {} service {} to {}".format(state, name, runlevel)) warning("Cannot {} service {} to {}".format(state, name, runlevel))
warning("rc-update returned error code {!s}".format(ec)) warning("rc-update returned error code {!s}".format(ec))
if mandatory: if mandatory:
return (_("Cannot {} service {} to {}").format(state, name, runlevel), title = _("Cannot modify service")
_("rc-update {} call in chroot returned error code {}").format(state, ec) diagnostic = _("<code>rc-update {arg!s}</code> call in chroot returned error code {num!s}.").format(arg=state, num=ec)
return (title,
self.make_failure_description(state, name, runlevel) + " " + diagnostic
) )
else: else:
warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
if mandatory: if mandatory:
return (_("Target runlevel {} does not exist for {}.").format(runlevel, name), title = _("Target runlevel does not exist")
_("No {} found.").format(runlevel_path)) diagnostic = _("The path for runlevel {level!s} is <code>{path!s}</code>, which does not exist.").format(level=runlevel, path=runlevel_path)
return (title,
self.make_failure_description(state, name, runlevel) + " " + diagnostic
)
else: else:
warning("Target service {} does not exist in {}.".format(name, self.initdDir)) warning("Target service {} does not exist in {}.".format(name, self.initdDir))
if mandatory: if mandatory:
return (_("Target service {} does not exist.").format(name), title = _("Target service does not exist")
_("No {} found.").format(service_path)) diagnostic = _("The path for service {name!s} is <code>{path!s}</code>, which does not exist.").format(name=name, path=service_path)
return (title,
self.make_failure_description(state, name, runlevel) + " " + diagnostic
)
def run(self): def run(self):

View File

@ -65,8 +65,24 @@ def systemctl(targets, command, suffix):
"systemctl {} call in chroot returned error code {}".format(command, ec) "systemctl {} call in chroot returned error code {}".format(command, ec)
) )
if mandatory: if mandatory:
return (_("Cannot {} systemd {} {}").format(command, suffix, name), title = _("Cannot modify service")
_("systemctl {} call in chroot returned error code {}").format(command, ec) diagnostic = _("<code>systemctl {arg!s}</code> call in chroot returned error code {num!s}.").format(arg=command, num=ec)
if command == "enable" and suffix == ".service":
description = _("Cannot enable systemd service <code>{name!s}</code>.")
elif command == "enable" and suffix == ".target":
description = _("Cannot enable systemd target <code>{name!s}</code>.")
elif command == "disable" and suffix == ".service":
description = _("Cannot enable systemd service <code>{name!s}</code>.")
elif command == "disable" and suffix == ".target":
description = _("Cannot disable systemd target <code>{name!s}</code>.")
elif command == "mask":
description = _("Cannot mask systemd unit <code>{name!s}</code>.")
else:
description = _("Unknown systemd commands <code>{command!s}</code> and <code>{suffix!s}</code> for unit {name!s}.")
return (title,
description.format(name=name, command=command, suffix=suffix) + " " + diagnostic
) )
return None return None