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