feat(installer): translate the progress messages and the log view
This commit is contained in:
1 file changed
+53
-8
+53
-8
@@ -23,6 +23,7 @@
|
|||||||
# switching to a console, and the failures that matter (no EFI partition,
|
# switching to a console, and the failures that matter (no EFI partition,
|
||||||
# no initramfs) are written as CRITIQUE in exactly those files.
|
# no initramfs) are written as CRITIQUE in exactly those files.
|
||||||
#
|
#
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
@@ -43,6 +44,7 @@ from pyanaconda.modules.common.constants.services import RUNTIME
|
|||||||
from pyanaconda.modules.common.structures.reboot import RebootData
|
from pyanaconda.modules.common.structures.reboot import RebootData
|
||||||
from pyanaconda.ui.gui.hubs.summary import SummaryHub
|
from pyanaconda.ui.gui.hubs.summary import SummaryHub
|
||||||
from pyanaconda.ui.gui.spokes import StandaloneSpoke
|
from pyanaconda.ui.gui.spokes import StandaloneSpoke
|
||||||
|
from pyanaconda.ui.gui.spokes.fws_i18n import t
|
||||||
from pyanaconda.ui.gui.utils import gtk_call_once
|
from pyanaconda.ui.gui.utils import gtk_call_once
|
||||||
from pyanaconda.ui.lib.installation_progress_error import InstallationProgressErrorMixin
|
from pyanaconda.ui.lib.installation_progress_error import InstallationProgressErrorMixin
|
||||||
|
|
||||||
@@ -53,15 +55,45 @@ __all__ = ["ProgressSpoke"]
|
|||||||
# Logs shown by the journal toggle, in the order the installation writes them.
|
# Logs shown by the journal toggle, in the order the installation writes them.
|
||||||
# The target path is completed with conf.target.system_root at runtime.
|
# The target path is completed with conf.target.system_root at runtime.
|
||||||
FWS_LOGS = (
|
FWS_LOGS = (
|
||||||
("pré-installation (live)", "/tmp/fws-pre.log"),
|
("fws:progress.log_pre", "/tmp/fws-pre.log"),
|
||||||
("préparation du disque (live)", "/tmp/fws-post-nochroot.log"),
|
("fws:progress.log_post_nochroot", "/tmp/fws-post-nochroot.log"),
|
||||||
("système installé", "var/log/fws-post.log"),
|
("fws:progress.log_post", "var/log/fws-post.log"),
|
||||||
)
|
)
|
||||||
FWS_LOG_POLL_MS = 1000
|
FWS_LOG_POLL_MS = 1000
|
||||||
# A log that is already large when the view opens is shown from its tail.
|
# A log that is already large when the view opens is shown from its tail.
|
||||||
FWS_LOG_BACKLOG = 256 * 1024
|
FWS_LOG_BACKLOG = 256 * 1024
|
||||||
FWS_LOG_MAX_CHARS = 2_000_000
|
FWS_LOG_MAX_CHARS = 2_000_000
|
||||||
|
|
||||||
|
FWS_KEY_PREFIX = "fws:"
|
||||||
|
|
||||||
|
|
||||||
|
def _fws_render(message):
|
||||||
|
"""Text to show for a progress message, in the installer's language.
|
||||||
|
|
||||||
|
FWS messages are a translation key with the "fws:" prefix, optionally
|
||||||
|
followed by a space and a JSON object of named fields (see
|
||||||
|
pyanaconda/modules/runtime/scripts/runtime.py). They are translated here,
|
||||||
|
at display time, because t() follows the language picked on the first
|
||||||
|
screen, which Anaconda stores in this process's $LANG. String fields are
|
||||||
|
rendered first, so a script's own key can sit inside a composed message.
|
||||||
|
Anything else is shown as is: Anaconda's messages are already translated
|
||||||
|
by gettext, and a plain text from a script must keep working.
|
||||||
|
"""
|
||||||
|
if not message.startswith(FWS_KEY_PREFIX):
|
||||||
|
return message
|
||||||
|
key, _sep, payload = message[len(FWS_KEY_PREFIX):].partition(" ")
|
||||||
|
fields = {}
|
||||||
|
if payload:
|
||||||
|
try:
|
||||||
|
fields = json.loads(payload)
|
||||||
|
except ValueError:
|
||||||
|
return message
|
||||||
|
if not isinstance(fields, dict):
|
||||||
|
return message
|
||||||
|
fields = {name: _fws_render(value) if isinstance(value, str) else value
|
||||||
|
for name, value in fields.items()}
|
||||||
|
return t(key, **fields)
|
||||||
|
|
||||||
|
|
||||||
class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
||||||
"""
|
"""
|
||||||
@@ -168,6 +200,7 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
|||||||
from pyanaconda.modules.common.constants.services import BOSS
|
from pyanaconda.modules.common.constants.services import BOSS
|
||||||
|
|
||||||
super().refresh()
|
super().refresh()
|
||||||
|
self._fws_set_toggle_label()
|
||||||
|
|
||||||
# Wait for background threads to finish
|
# Wait for background threads to finish
|
||||||
if thread_manager.running > 1:
|
if thread_manager.running > 1:
|
||||||
@@ -201,7 +234,8 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
|||||||
def _fws_build_log_view(self):
|
def _fws_build_log_view(self):
|
||||||
box = self.builder.get_object("progressBox")
|
box = self.builder.get_object("progressBox")
|
||||||
|
|
||||||
self._fws_toggle = Gtk.ToggleButton(label="Afficher le journal")
|
self._fws_toggle = Gtk.ToggleButton()
|
||||||
|
self._fws_set_toggle_label()
|
||||||
self._fws_toggle.set_halign(Gtk.Align.START)
|
self._fws_toggle.set_halign(Gtk.Align.START)
|
||||||
self._fws_toggle.connect("toggled", self._fws_on_toggled)
|
self._fws_toggle.connect("toggled", self._fws_on_toggled)
|
||||||
box.pack_start(self._fws_toggle, False, False, 6)
|
box.pack_start(self._fws_toggle, False, False, 6)
|
||||||
@@ -233,16 +267,23 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
|||||||
self._fws_last_tag = None
|
self._fws_last_tag = None
|
||||||
self._fws_timer = None
|
self._fws_timer = None
|
||||||
|
|
||||||
|
def _fws_set_toggle_label(self):
|
||||||
|
# Also called from refresh(): the spoke can be built before the user
|
||||||
|
# picks the language, the label must follow the language when shown.
|
||||||
|
if self._fws_toggle.get_active():
|
||||||
|
self._fws_toggle.set_label(t("progress.log_hide"))
|
||||||
|
else:
|
||||||
|
self._fws_toggle.set_label(t("progress.log_show"))
|
||||||
|
|
||||||
def _fws_on_toggled(self, button):
|
def _fws_on_toggled(self, button):
|
||||||
|
self._fws_set_toggle_label()
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
button.set_label("Masquer le journal")
|
|
||||||
self._fws_scroll.show()
|
self._fws_scroll.show()
|
||||||
self._fws_poll()
|
self._fws_poll()
|
||||||
if self._fws_timer is None:
|
if self._fws_timer is None:
|
||||||
self._fws_timer = GLib.timeout_add(FWS_LOG_POLL_MS,
|
self._fws_timer = GLib.timeout_add(FWS_LOG_POLL_MS,
|
||||||
self._fws_poll)
|
self._fws_poll)
|
||||||
else:
|
else:
|
||||||
button.set_label("Afficher le journal")
|
|
||||||
self._fws_scroll.hide()
|
self._fws_scroll.hide()
|
||||||
if self._fws_timer is not None:
|
if self._fws_timer is not None:
|
||||||
GLib.source_remove(self._fws_timer)
|
GLib.source_remove(self._fws_timer)
|
||||||
@@ -268,7 +309,9 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
|||||||
entry["offset"] += len(data)
|
entry["offset"] += len(data)
|
||||||
text = data.decode("utf-8", errors="replace")
|
text = data.decode("utf-8", errors="replace")
|
||||||
if self._fws_last_tag != entry["tag"]:
|
if self._fws_last_tag != entry["tag"]:
|
||||||
text = f"\n── {entry['tag']} : {entry['path']} ──\n{text}"
|
header = t("progress.log_header", name=_fws_render(entry["tag"]),
|
||||||
|
path=entry["path"])
|
||||||
|
text = f"\n{header}\n{text}"
|
||||||
self._fws_last_tag = entry["tag"]
|
self._fws_last_tag = entry["tag"]
|
||||||
self._fws_append(text)
|
self._fws_append(text)
|
||||||
return True
|
return True
|
||||||
@@ -285,7 +328,9 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
|
|||||||
def _on_progress_changed(self, step, message):
|
def _on_progress_changed(self, step, message):
|
||||||
"""Handle a new progress report."""
|
"""Handle a new progress report."""
|
||||||
if message:
|
if message:
|
||||||
gtk_call_once(self._progressLabel.set_text, message)
|
# FWS: the post-install scripts send translation keys (see
|
||||||
|
# _fws_render); other messages go through unchanged.
|
||||||
|
gtk_call_once(self._progressLabel.set_text, _fws_render(message))
|
||||||
|
|
||||||
if self._task_proxy.Steps > 0:
|
if self._task_proxy.Steps > 0:
|
||||||
gtk_call_once(self._progressBar.set_fraction, step/self._task_proxy.Steps)
|
gtk_call_once(self._progressBar.set_fraction, step/self._task_proxy.Steps)
|
||||||
Reference in new issue
Block a user