feat(installer): translate the progress messages and the log view

This commit is contained in:
nocode committed 2026-11-26 14:00:06 +01:00
1 parent 299039fe6f
commit f01a49cc60
1 file changed
+53 -8
@@ -23,6 +23,7 @@
# switching to a console, and the failures that matter (no EFI partition,
# no initramfs) are written as CRITIQUE in exactly those files.
#
import json
import os
import gi
@@ -43,6 +44,7 @@ from pyanaconda.modules.common.constants.services import RUNTIME
from pyanaconda.modules.common.structures.reboot import RebootData
from pyanaconda.ui.gui.hubs.summary import SummaryHub
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.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.
# The target path is completed with conf.target.system_root at runtime.
FWS_LOGS = (
("pré-installation (live)", "/tmp/fws-pre.log"),
("préparation du disque (live)", "/tmp/fws-post-nochroot.log"),
("système installé", "var/log/fws-post.log"),
("fws:progress.log_pre", "/tmp/fws-pre.log"),
("fws:progress.log_post_nochroot", "/tmp/fws-post-nochroot.log"),
("fws:progress.log_post", "var/log/fws-post.log"),
)
FWS_LOG_POLL_MS = 1000
# A log that is already large when the view opens is shown from its tail.
FWS_LOG_BACKLOG = 256 * 1024
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):
"""
@@ -168,6 +200,7 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
from pyanaconda.modules.common.constants.services import BOSS
super().refresh()
self._fws_set_toggle_label()
# Wait for background threads to finish
if thread_manager.running > 1:
@@ -201,7 +234,8 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
def _fws_build_log_view(self):
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.connect("toggled", self._fws_on_toggled)
box.pack_start(self._fws_toggle, False, False, 6)
@@ -233,16 +267,23 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
self._fws_last_tag = 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):
self._fws_set_toggle_label()
if button.get_active():
button.set_label("Masquer le journal")
self._fws_scroll.show()
self._fws_poll()
if self._fws_timer is None:
self._fws_timer = GLib.timeout_add(FWS_LOG_POLL_MS,
self._fws_poll)
else:
button.set_label("Afficher le journal")
self._fws_scroll.hide()
if self._fws_timer is not None:
GLib.source_remove(self._fws_timer)
@@ -268,7 +309,9 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
entry["offset"] += len(data)
text = data.decode("utf-8", errors="replace")
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_append(text)
return True
@@ -285,7 +328,9 @@ class ProgressSpoke(StandaloneSpoke, InstallationProgressErrorMixin):
def _on_progress_changed(self, step, message):
"""Handle a new progress report."""
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:
gtk_call_once(self._progressBar.set_fraction, step/self._task_proxy.Steps)