feat(i18n): translate fws-drivers

This commit is contained in:
nocode committed 2026-11-26 18:18:27 +01:00
1 parent 07827c3dbd
commit 6c78bb456b
1 file changed
+63 -82
@@ -12,10 +12,14 @@
# fws-setup-hardware --groups a,b <bureau>→ installation avancée
# fws-setup-hardware --check → vérification/réparation seule
#
# Texts come from system-translations.toml (drivers.* keys); the group names
# come translated from the engine's plan (hardware.* keys).
#
# GTK3 : présent sur TOUS les bureaux FWS (Firefox le tire) ; python-gobject
# est installé avec le bureau par le kickstart — mêmes prérequis que fws-hello.
import os
import shlex
import shutil
import subprocess
import sys
@@ -27,6 +31,11 @@ gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0") # sinon gi charge Gdk 4.0 (conflit avec Gtk3)
from gi.repository import Gdk, GLib, Gtk # noqa: E402
sys.path.insert(0, "/usr/local/lib/fws")
from fws_i18n import catalog # noqa: E402
t = catalog("system").t
# WM_CLASS déterministe : les règles i3/Hyprland « fenêtre flottante » ciblent
# cette classe.
GLib.set_prgname("fws-drivers")
@@ -78,8 +87,8 @@ def _privileged_argv(args):
term = _terminal()
if term is None:
return ["sh", "-c", "sudo " + " ".join([_ENGINE] + args)], False
command = ("sudo " + " ".join([_ENGINE] + args)
+ "; echo; echo 'Appuie sur Entrée pour fermer.'; read _")
command = ("sudo " + " ".join([_ENGINE] + args) + "; echo; echo "
+ shlex.quote(t("common.press_enter_to_close")) + "; read _")
if term == "gnome-terminal":
return [term, "--", "sh", "-c", command], False
return [term, "-e", "sh", "-c", command], False
@@ -129,7 +138,7 @@ def _big_button(label, description):
class DriversWindow(Gtk.Window):
def __init__(self, autostart=False):
super().__init__(title="FWS — Pilotes et matériel")
super().__init__(title=t("drivers.window_title"))
self._autostart = autostart
self.set_default_size(560, -1)
self.set_position(Gtk.WindowPosition.CENTER)
@@ -154,40 +163,30 @@ class DriversWindow(Gtk.Window):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
title = Gtk.Label()
title.set_markup("<span size='x-large' weight='bold'>Pilotes et matériel</span>")
title.set_markup("<span size='x-large' weight='bold'>"
f"{GLib.markup_escape_text(t('drivers.title'))}</span>")
title.set_xalign(0)
box.pack_start(title, False, False, 0)
subtitle = Gtk.Label(
label="Tout ce qu'il faut pour que ta machine fonctionne au mieux : "
"affichage, son, Bluetooth, luminosité, imprimante, jeux.")
subtitle = Gtk.Label(label=t("drivers.subtitle"))
subtitle.set_line_wrap(True)
subtitle.set_xalign(0)
box.pack_start(subtitle, False, False, 0)
simple = _big_button(
"Installation simple (recommandé)",
"FWS installe ce dont ta machine a besoin, puis s'assure que "
"l'affichage, le son, le Bluetooth et le réseau fonctionnent. "
"Ajoute aussi les codecs audio/vidéo, Steam + Wine et la réalité "
"virtuelle : plusieurs gigaoctets, compte un bon moment selon ta "
"connexion. Tu n'as rien à choisir.")
simple = _big_button(t("drivers.simple_label"),
t("drivers.simple_description"))
simple.connect("clicked", self._on_simple)
box.pack_start(simple, False, False, 0)
advanced = _big_button(
"Installation avancée",
"Pour décider toi-même de ce qui s'installe. Ce qui a été reconnu "
"sur ta machine est déjà coché.")
advanced = _big_button(t("drivers.advanced_label"),
t("drivers.advanced_description"))
advanced.connect("clicked", self._on_advanced)
box.pack_start(advanced, False, False, 0)
box.pack_start(Gtk.Separator(), False, False, 6)
check = _big_button(
"Vérifier et réparer seulement",
"N'installe rien. Regarde si le son, le Bluetooth, le réseau et "
"l'imprimante répondent, et les remet en route si besoin.")
check = _big_button(t("drivers.check_label"),
t("drivers.check_description"))
check.connect("clicked", self._on_check)
box.pack_start(check, False, False, 0)
@@ -195,12 +194,11 @@ class DriversWindow(Gtk.Window):
# à la main, elle n'a aucune raison de se faire taire.
self._again = None
if self._autostart:
self._again = Gtk.CheckButton(
label="Ne plus me le proposer au démarrage")
self._again = Gtk.CheckButton(label=t("drivers.dont_offer_again"))
self._again.set_active(False)
box.pack_start(self._again, False, False, 6)
close = Gtk.Button(label="Fermer")
close = Gtk.Button(label=t("common.close"))
close.connect("clicked", lambda _b: self.close())
box.pack_start(close, False, False, 6)
return box
@@ -210,13 +208,12 @@ class DriversWindow(Gtk.Window):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
title = Gtk.Label()
title.set_markup("<span size='x-large' weight='bold'>Installation avancée</span>")
title.set_markup("<span size='x-large' weight='bold'>"
f"{GLib.markup_escape_text(t('drivers.advanced_label'))}</span>")
title.set_xalign(0)
box.pack_start(title, False, False, 0)
hint = Gtk.Label(
label="Ce qui a été reconnu sur ta machine est coché. "
"Décoche ce dont tu ne veux pas.")
hint = Gtk.Label(label=t("drivers.advanced_hint"))
hint.set_line_wrap(True)
hint.set_xalign(0)
hint.get_style_context().add_class("dim-label")
@@ -237,7 +234,7 @@ class DriversWindow(Gtk.Window):
head = Gtk.Label()
mark = GLib.markup_escape_text(label)
if not detected:
mark += " <i>(non détecté sur cette machine)</i>"
mark += f" <i>{GLib.markup_escape_text(t('drivers.not_detected'))}</i>"
head.set_markup(mark)
head.set_xalign(0)
head.set_line_wrap(True)
@@ -254,10 +251,10 @@ class DriversWindow(Gtk.Window):
buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
buttons.set_halign(Gtk.Align.END)
back = Gtk.Button(label="Précédent")
back = Gtk.Button(label=t("drivers.back_button"))
back.connect("clicked",
lambda _b: self._stack.set_visible_child_name("home"))
install = Gtk.Button(label="Installer la sélection")
install = Gtk.Button(label=t("drivers.install_selection_button"))
install.get_style_context().add_class("suggested-action")
install.connect("clicked", self._on_install_selection)
buttons.pack_start(back, False, False, 0)
@@ -295,21 +292,19 @@ class DriversWindow(Gtk.Window):
self._spinner = Gtk.Spinner()
self._spinner.start()
row.pack_start(self._spinner, False, False, 0)
self._status = Gtk.Label(label="Préparation…")
self._status = Gtk.Label(label=t("drivers.status_preparing"))
self._status.set_xalign(0)
self._status.set_line_wrap(True)
row.pack_start(self._status, True, True, 0)
box.pack_start(row, False, False, 0)
self._reassure = Gtk.Label(
label="Tu peux laisser cette fenêtre ouverte, il n'y a rien à faire. "
"Évite juste d'éteindre la machine maintenant.")
self._reassure = Gtk.Label(label=t("drivers.reassurance"))
self._reassure.set_line_wrap(True)
self._reassure.set_xalign(0)
self._reassure.get_style_context().add_class("dim-label")
box.pack_start(self._reassure, False, False, 0)
expander = Gtk.Expander(label="Afficher les détails")
expander = Gtk.Expander(label=t("drivers.show_details"))
scroll = Gtk.ScrolledWindow()
scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scroll.set_min_content_height(240)
@@ -321,7 +316,7 @@ class DriversWindow(Gtk.Window):
expander.add(scroll)
box.pack_start(expander, True, True, 0)
self._close = Gtk.Button(label="Fermer")
self._close = Gtk.Button(label=t("common.close"))
self._close.set_sensitive(False)
self._close.connect("clicked", lambda _b: self.close())
box.pack_start(self._close, False, False, 0)
@@ -342,8 +337,7 @@ class DriversWindow(Gtk.Window):
# Repli terminal : impossible de suivre la sortie depuis ici.
subprocess.Popen(argv) # noqa: S603 — commandes internes FWS
self._spinner.stop()
self._status.set_text(
"La suite se passe dans la fenêtre de terminal qui vient de s'ouvrir.")
self._status.set_text(t("drivers.status_in_terminal"))
self._reassure.hide()
self._close.set_sensitive(True)
return
@@ -364,31 +358,24 @@ class DriversWindow(Gtk.Window):
self._proc.wait()
GLib.idle_add(self._finished, self._proc.returncode, None)
# Traduction des étapes du moteur en phrases lisibles. Les libellés bruts
# restent dans les détails.
_STEPS = (
("groupe «", "Installation : "),
("installation :", "Téléchargement et installation des paquets…"),
("vérification des services", "Vérification de ton matériel…"),
("synchro pacman", "Mise à jour de la liste des logiciels…"),
)
# Engine steps turned into readable sentences, by the tag of their line
# ("[FWS-hw:install] …"): the engine's text is translated, possibly into
# another language than the window's (pkexec runs it with the system's), so
# only the tag is read. The raw lines stay in the details.
_STEP_PREFIX = "[FWS-hw:"
_STEPS = {
"install": "drivers.status_installing",
"check": "drivers.status_checking",
}
def _append(self, line):
buf = self._log.get_buffer()
buf.insert(buf.get_end_iter(), line + "\n")
self._log.scroll_to_iter(buf.get_end_iter(), 0.0, False, 0.0, 0.0)
if not line.startswith("[FWS-hw]"):
return False
text = line.split("]", 1)[1].strip()
for needle, friendly in self._STEPS:
if needle in text:
if friendly.endswith(": "):
# « groupe « Pilotes graphiques — … » » → « Pilotes graphiques »
label = text.split("«", 1)[1].rsplit("»", 1)[0]
self._status.set_text(friendly + label.split("—")[0].strip())
else:
self._status.set_text(friendly)
return False
if line.startswith(self._STEP_PREFIX):
step = line[len(self._STEP_PREFIX):].split("]", 1)[0]
if step in self._STEPS:
self._status.set_text(t(self._STEPS[step]))
return False
def _finished(self, code, error):
@@ -396,31 +383,27 @@ class DriversWindow(Gtk.Window):
self._reassure.hide()
self._close.set_sensitive(True)
if error is not None:
self._status.set_markup(
"<b>Impossible de lancer l'installation.</b>\n"
+ GLib.markup_escape_text(error))
self._show_result(t("drivers.launch_failed"), error)
return
if code == 0:
self._status.set_markup(
"<b>C'est prêt.</b>\nSi des pilotes graphiques viennent d'être "
"installés, redémarre pour qu'ils prennent effet.")
self._show_result(t("drivers.done_title"), t("drivers.done_body"))
elif code == 126:
# pkexec : authentification refusée ou annulée.
self._status.set_markup(
"<b>Annulé.</b>\nRien n'a été modifié — le mot de passe "
"administrateur n'a pas été validé.")
self._show_result(t("drivers.cancelled_title"), t("drivers.cancelled_body"))
else:
self._status.set_markup(
"<b>Tout n'a pas abouti.</b>\nLe plus souvent c'est la connexion "
"Internet. Vérifie-la puis réessaie ; les détails ci-dessous "
"disent ce qui a échoué.")
self._show_result(t("drivers.failed_title"), t("drivers.failed_body"))
def _show_result(self, title, body):
"""Status line: `title` in bold, then `body` on the next line."""
self._status.set_markup(f"<b>{GLib.markup_escape_text(title)}</b>\n"
+ GLib.markup_escape_text(body))
# ---------------------------------------------------------------- actions
def _on_simple(self, _button):
self._start(["--all", self._session], "Installation du nécessaire")
self._start(["--all", self._session], t("drivers.simple_heading"))
def _on_check(self, _button):
self._start(["--check"], "Vérification du matériel")
self._start(["--check"], t("drivers.check_heading"))
def _on_advanced(self, _button):
groups = _plan(self._session)
@@ -428,10 +411,9 @@ class DriversWindow(Gtk.Window):
dialog = Gtk.MessageDialog(
transient_for=self, modal=True,
message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK,
text="Impossible de lister le matériel")
text=t("drivers.plan_failed_title"))
dialog.format_secondary_text(
f"« {_ENGINE} --plan » n'a rien renvoyé. "
"L'installation simple reste utilisable.")
t("drivers.plan_failed_detail", command=f"{_ENGINE} --plan"))
dialog.run()
dialog.destroy()
return
@@ -449,7 +431,7 @@ class DriversWindow(Gtk.Window):
self._stack.set_visible_child_name("home")
return
self._start(["--groups", ",".join(chosen), self._session],
"Installation de ta sélection")
t("drivers.selection_heading"))
def main():
@@ -460,11 +442,10 @@ def main():
if os.path.exists(_SYSTEM_DONE) or os.path.exists(_USER_DONE):
return 0
if not Gtk.init_check()[0]:
print("Aucun serveur graphique : utilise « sudo fws-setup-hardware » "
"en console.", file=sys.stderr)
print(t("drivers.no_display", command=f"sudo {_ENGINE}"), file=sys.stderr)
return 1
if shutil.which(_ENGINE) is None:
print(f"{_ENGINE} est absent de cette image.", file=sys.stderr)
print(t("drivers.engine_missing", command=_ENGINE), file=sys.stderr)
return 1
window = DriversWindow(autostart=autostart)
window.connect("destroy", lambda _w: Gtk.main_quit())