From 4178d5841c9486399bfa65232f68f6c915b1956d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Feb 2019 12:36:17 +0100 Subject: [PATCH 1/4] [modules] Enable translations on some Python modules - Python modules should have human-readable names, which means that the description should be translated in `pretty_name()` --- src/modules/machineid/main.py | 1 + src/modules/plymouthcfg/main.py | 11 +++++++++++ src/modules/removeuser/main.py | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index c4c473246..092fc7196 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -6,6 +6,7 @@ # Copyright 2014, Kevin Kofler # Copyright 2016, Philip Müller # Copyright 2017, Alf Gaida +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/src/modules/plymouthcfg/main.py b/src/modules/plymouthcfg/main.py index 6f1128b7e..e224f5df0 100644 --- a/src/modules/plymouthcfg/main.py +++ b/src/modules/plymouthcfg/main.py @@ -6,6 +6,7 @@ # Copyright 2016, Artoo # Copyright 2017, Alf Gaida # Copyright 2018, Gabriel Craciunescu +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +25,16 @@ import libcalamares from libcalamares.utils import debug, target_env_call +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure Plymouth theme") + class PlymouthController: diff --git a/src/modules/removeuser/main.py b/src/modules/removeuser/main.py index 9acc20b54..bd876edcd 100644 --- a/src/modules/removeuser/main.py +++ b/src/modules/removeuser/main.py @@ -5,6 +5,7 @@ # # Copyright 2015, Teo Mrnjavac # Copyright 2017. Alf Gaida +# Copyright 2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +23,16 @@ import subprocess import libcalamares +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Remove live user from target system") + def run(): """ From c9f89e292974cc65c9e2705514e8ba10f5797166 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Feb 2019 15:29:04 +0100 Subject: [PATCH 2/4] [modules] Translate name of services-* modules. --- src/modules/services-openrc/main.py | 13 ++++++++++++- src/modules/services-systemd/main.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/modules/services-openrc/main.py b/src/modules/services-openrc/main.py index c3e14b481..34f80cdf2 100644 --- a/src/modules/services-openrc/main.py +++ b/src/modules/services-openrc/main.py @@ -6,7 +6,7 @@ # Copyright 2016, Artoo # Copyright 2017, Philip Müller # Copyright 2018, Artoo -# Copyright 2018, Adriaan de Groot +# Copyright 2018-2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,6 +27,17 @@ from libcalamares.utils import target_env_call, warning from os.path import exists, join +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure OpenRC services") + + class OpenrcController: """ This is the openrc service controller. diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py index 09263b9f0..7367f988c 100644 --- a/src/modules/services-systemd/main.py +++ b/src/modules/services-systemd/main.py @@ -6,7 +6,7 @@ # Copyright 2014, Philip Müller # Copyright 2014, Teo Mrnjavac # Copyright 2017, Alf Gaida -# Copyright 2018, Adriaan de Groot +# Copyright 2018-2019, Adriaan de Groot # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,17 @@ import libcalamares +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +def pretty_name(): + return _("Configure systemd services") + + def systemctl(targets, command, suffix): """ For each entry in @p targets, run "systemctl ", From 544c1b708c1518117edf40047200cdf1dcd50c2f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Feb 2019 18:50:29 +0100 Subject: [PATCH 3/4] [services-openrc] Make user-visible messages translatable --- src/modules/services-openrc/main.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/modules/services-openrc/main.py b/src/modules/services-openrc/main.py index 34f80cdf2..46890dd98 100644 --- a/src/modules/services-openrc/main.py +++ b/src/modules/services-openrc/main.py @@ -80,24 +80,22 @@ class OpenrcController: if exists(runlevel_path): ec = target_env_call(["rc-update", state, name, runlevel]) if ec != 0: + 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) + return (_("Cannot {} service {} to {}").format(state, name, runlevel), + _("rc-update {} call in chroot returned error code {}").format(state, ec) ) - else: - warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec)) 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)) - else: - warning("Target runlevel {} does not exist for {}.".format(runlevel, name)) + return (_("Target runlevel {} does not exist for {}.").format(runlevel, name), + _("No {} found.").format(runlevel_path)) 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)) - else: - warning("Target service {} does not exist in {}.".format(name, self.initdDir)) + return (_("Target service {} does not exist.").format(name), + _("No {} found.").format(service_path)) def run(self): From b7c77e7323f4a972ff5de427c27c2832a3befb5c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 14 Feb 2019 18:52:19 +0100 Subject: [PATCH 4/4] [services-systemd] Make user-visible messages translatable --- src/modules/services-systemd/main.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py index 7367f988c..1cb5899ae 100644 --- a/src/modules/services-systemd/main.py +++ b/src/modules/services-systemd/main.py @@ -58,17 +58,16 @@ def systemctl(targets, command, suffix): ) if ec != 0: + libcalamares.utils.warning( + "Cannot {} systemd {} {}".format(command, suffix, name) + ) + libcalamares.utils.warning( + "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) + return (_("Cannot {} systemd {} {}").format(command, suffix, name), + _("systemctl {} call in chroot returned error code {}").format(command, ec) ) - else: - libcalamares.utils.warning( - "Cannot {} systemd {} {}".format(command, suffix, name) - ) - libcalamares.utils.warning( - "systemctl {} call in chroot returned error code {}".format(command, ec) - ) return None @@ -103,6 +102,4 @@ def run(): if r is not None: return r - - # This could have just been return r return None