diff --git a/configs/releng/airootfs/usr/local/bin/fws-powermenu b/configs/releng/airootfs/usr/local/bin/fws-powermenu index 4002796..3059083 100755 --- a/configs/releng/airootfs/usr/local/bin/fws-powermenu +++ b/configs/releng/airootfs/usr/local/bin/fws-powermenu @@ -9,10 +9,14 @@ import os import subprocess import sys +sys.path.insert(0, "/usr/local/lib/fws") +from fws_i18n import catalog # noqa: E402 + +t = catalog("system").t + _WOFI_STYLE = "/usr/local/share/fws/wofi-style.css" _HYPR = bool(os.environ.get("HYPRLAND_INSTANCE_SIGNATURE")) -# (libellé affiché, commande shell). L'icône Nerd Font aide au repérage. if _HYPR: _lock = "hyprlock" _logout = "hyprctl dispatch exit" @@ -20,24 +24,26 @@ else: _lock = "i3lock -c 1e1e2e" _logout = "i3-msg exit" +# (Nerd Font icon, label key, shell command). The icon stays out of the +# translated text: it is the same in every language. _ITEMS = [ - ("󰌾 Verrouiller", _lock), - ("󰗽 Déconnexion", _logout), - ("󰤄 Suspendre", "systemctl suspend"), - ("󰜉 Redémarrer", "systemctl reboot"), - ("󰐥 Éteindre", "systemctl poweroff"), + ("󰌾", "powermenu.lock", _lock), + ("󰗽", "powermenu.log_out", _logout), + ("󰤄", "powermenu.suspend", "systemctl suspend"), + ("󰜉", "powermenu.restart", "systemctl reboot"), + ("󰐥", "powermenu.shut_down", "systemctl poweroff"), ] def _menu(entries): text = "\n".join(entries) if _HYPR: - cmd = ["wofi", "--dmenu", "--prompt", "Alimentation", + cmd = ["wofi", "--dmenu", "--prompt", t("powermenu.prompt"), "--width", "300", "--height", "260", "--cache-file", "/dev/null"] if os.path.exists(_WOFI_STYLE): cmd += ["--style", _WOFI_STYLE] else: - cmd = ["rofi", "-dmenu", "-i", "-p", "Alimentation", "-no-custom", + cmd = ["rofi", "-dmenu", "-i", "-p", t("powermenu.prompt"), "-no-custom", "-theme-str", "window { width: 300px; } listview { lines: 5; }"] out = subprocess.run(cmd, input=text, text=True, capture_output=True, check=False) @@ -45,10 +51,13 @@ def _menu(entries): def main(): - choice = _menu([label for label, _ in _ITEMS]) + # The menu returns the chosen line: it is matched back to its command by + # the very labels it was given. + items = [(f"{icon} {t(key)}", command) for icon, key, command in _ITEMS] + choice = _menu([label for label, _ in items]) if not choice: return 0 - for label, command in _ITEMS: + for label, command in items: if label == choice: subprocess.Popen(["sh", "-c", command]) # noqa: S603,S607 break