feat(i18n): translate fws-keys, including the Hyprland bind descriptions
This commit is contained in:
1 file changed
+46
-19
@@ -13,33 +13,60 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, "/usr/local/lib/fws")
|
||||||
|
from fws_i18n import catalog # noqa: E402
|
||||||
|
|
||||||
|
_catalog = catalog("system")
|
||||||
|
t = _catalog.t
|
||||||
|
|
||||||
_WOFI_STYLE = "/usr/local/share/fws/wofi-keys.css"
|
_WOFI_STYLE = "/usr/local/share/fws/wofi-keys.css"
|
||||||
|
|
||||||
# Bits de modmask Hyprland (masques X11) dans l'ordre d'affichage voulu.
|
# Bits de modmask Hyprland (masques X11) dans l'ordre d'affichage voulu.
|
||||||
_MODS = [(64, "SUPER"), (4, "CTRL"), (8, "ALT"), (1, "SHIFT")]
|
_MODS = [(64, "SUPER"), (4, "CTRL"), (8, "ALT"), (1, "SHIFT")]
|
||||||
|
|
||||||
|
# Key names translated for display (keys of system-translations.toml).
|
||||||
_KEY_LABELS = {
|
_KEY_LABELS = {
|
||||||
"mouse:272": "clic gauche",
|
"mouse:272": "keys.left_click",
|
||||||
"mouse:273": "clic droit",
|
"mouse:273": "keys.right_click",
|
||||||
"mouse:274": "clic molette",
|
"mouse:274": "keys.middle_click",
|
||||||
"mouse_down": "molette bas",
|
"mouse_down": "keys.wheel_down",
|
||||||
"mouse_up": "molette haut",
|
"mouse_up": "keys.wheel_up",
|
||||||
"button4": "molette haut",
|
"button4": "keys.wheel_up",
|
||||||
"button5": "molette bas",
|
"button5": "keys.wheel_down",
|
||||||
"return": "Entrée",
|
"return": "keys.enter",
|
||||||
"space": "Espace",
|
"space": "keys.space",
|
||||||
"escape": "Échap",
|
"escape": "keys.escape",
|
||||||
"tab": "Tab",
|
"tab": "keys.tab",
|
||||||
|
"print": "keys.print_screen",
|
||||||
|
}
|
||||||
|
_KEY_SYMBOLS = {
|
||||||
"left": "←",
|
"left": "←",
|
||||||
"right": "→",
|
"right": "→",
|
||||||
"up": "↑",
|
"up": "↑",
|
||||||
"down": "↓",
|
"down": "↓",
|
||||||
"print": "Impr écran",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _label(key):
|
def _label(key):
|
||||||
return _KEY_LABELS.get(key.lower(), key)
|
name = key.lower()
|
||||||
|
if name in _KEY_LABELS:
|
||||||
|
return t(_KEY_LABELS[name])
|
||||||
|
return _KEY_SYMBOLS.get(name, key)
|
||||||
|
|
||||||
|
|
||||||
|
def _description(bind):
|
||||||
|
"""Description of a Hyprland bind, translated when it is an FWS key.
|
||||||
|
|
||||||
|
The FWS config writes keys (binds.open_terminal) as bindd descriptions:
|
||||||
|
a translated text with a comma in it would break the bind line, so they
|
||||||
|
are translated here instead of in the file. A user's own plain-text
|
||||||
|
description is shown as written.
|
||||||
|
"""
|
||||||
|
desc = (bind.get("description") or "").strip()
|
||||||
|
if desc.startswith("binds.") and _catalog.text(desc) is not None:
|
||||||
|
# The workspace binds share one text: their argument is the number.
|
||||||
|
return t(desc, number=(bind.get("arg") or "").strip())
|
||||||
|
return desc
|
||||||
|
|
||||||
|
|
||||||
# --- Hyprland : binds réels via hyprctl ------------------------------------
|
# --- Hyprland : binds réels via hyprctl ------------------------------------
|
||||||
@@ -54,7 +81,7 @@ def hyprland_lines():
|
|||||||
if not combo or combo in seen:
|
if not combo or combo in seen:
|
||||||
continue
|
continue
|
||||||
seen.add(combo)
|
seen.add(combo)
|
||||||
desc = (bind.get("description") or "").strip() \
|
desc = _description(bind) \
|
||||||
or f"{bind.get('dispatcher', '?')} {(bind.get('arg') or '').strip()}".strip()
|
or f"{bind.get('dispatcher', '?')} {(bind.get('arg') or '').strip()}".strip()
|
||||||
lines.append(f"{combo:<24} {desc}")
|
lines.append(f"{combo:<24} {desc}")
|
||||||
return lines
|
return lines
|
||||||
@@ -94,17 +121,17 @@ def i3_lines():
|
|||||||
|
|
||||||
def show(lines):
|
def show(lines):
|
||||||
if not lines:
|
if not lines:
|
||||||
lines = ["(aucun raccourci trouvé)"]
|
lines = [t("keys.none_found")]
|
||||||
text = "\n".join(lines)
|
text = "\n".join(lines)
|
||||||
if os.environ.get("HYPRLAND_INSTANCE_SIGNATURE"):
|
if os.environ.get("HYPRLAND_INSTANCE_SIGNATURE"):
|
||||||
cmd = ["wofi", "--dmenu", "--prompt", "Raccourcis clavier — taper pour filtrer",
|
cmd = ["wofi", "--dmenu", "--prompt", t("keys.prompt_filter"),
|
||||||
"--width", "820", "--height", "600", "--insensitive",
|
"--width", "820", "--height", "600", "--insensitive",
|
||||||
"--cache-file", "/dev/null"]
|
"--cache-file", "/dev/null"]
|
||||||
if os.path.exists(_WOFI_STYLE):
|
if os.path.exists(_WOFI_STYLE):
|
||||||
cmd += ["--style", _WOFI_STYLE]
|
cmd += ["--style", _WOFI_STYLE]
|
||||||
else:
|
else:
|
||||||
# X11/i3 : rofi en dmenu, style assorti (mono pour l'alignement).
|
# X11/i3 : rofi en dmenu, style assorti (mono pour l'alignement).
|
||||||
cmd = ["rofi", "-dmenu", "-i", "-p", "Raccourcis clavier",
|
cmd = ["rofi", "-dmenu", "-i", "-p", t("keys.prompt"),
|
||||||
"-no-custom",
|
"-no-custom",
|
||||||
"-theme-str", 'window { width: 880px; } listview { lines: 18; }',
|
"-theme-str", 'window { width: 880px; } listview { lines: 18; }',
|
||||||
"-theme-str", '* { font: "Noto Sans Mono 11"; }']
|
"-theme-str", '* { font: "Noto Sans Mono 11"; }']
|
||||||
@@ -118,8 +145,8 @@ def main():
|
|||||||
else:
|
else:
|
||||||
lines = i3_lines()
|
lines = i3_lines()
|
||||||
except Exception as exc: # noqa: BLE001 — best effort, jamais de crash muet
|
except Exception as exc: # noqa: BLE001 — best effort, jamais de crash muet
|
||||||
subprocess.run(["notify-send", "Raccourcis FWS", f"Erreur : {exc}"],
|
subprocess.run(["notify-send", t("keys.error_title"),
|
||||||
check=False)
|
t("keys.error", error=exc)], check=False)
|
||||||
return 1
|
return 1
|
||||||
show(lines)
|
show(lines)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in new issue
Block a user