feat(installer): set every keyboard layout and translate the bar labels

A language whose keyboard cannot type Latin letters now also gets a US
layout and a switch shortcut, in X11 and Hyprland alike. The waybar,
polybar and i3 labels are written in the language chosen at install.
This commit is contained in:
nocode committed 2026-11-26 18:18:26 +01:00
1 parent 4bce5e08a2
commit 2167322bb5
1 file changed
+81 -21
@@ -512,26 +512,72 @@ fws-install-step 28 fws:progress.keyboard_language
# kb_layout). LOCALE : le locale choisi (ex. fr_CH.UTF-8) doit être GÉNÉRÉ —
# Anaconda vient de Fedora (locales pré-générées) et ne lance pas locale-gen →
# sans ça LANG casse et tout retombe en C.
XL=""; XV=""
XKB="$(sed -n "s/.*--xlayouts=//p" /root/anaconda-ks.cfg 2>/dev/null | head -1)"
XKB="${XKB#[\'\"]}"; XKB="${XKB%%[\'\"]*}"; XKB="${XKB%%,*}" # 1re dispo, ex. « ch (fr) »
if [ -z "$XKB" ]; then
_loc="$(. /etc/locale.conf 2>/dev/null; printf '%s' "${LANG%%.*}")" # fr_CH
_lng="${_loc%%_*}"; _terr="${_loc#*_}"; [ "$_terr" = "$_loc" ] && _terr=""
[ -n "$_terr" ] && XKB="$(python3 -c "import langtable; k=langtable.list_keyboards(languageId='$_lng', territoryId='$_terr'); print(k[0] if k else '')" 2>/dev/null)"
fi
if [ -n "$XKB" ]; then
XL="${XKB%%(*}"; XL="${XL%% *}" # ch
case "$XKB" in *'('*')') XV="${XKB#*(}"; XV="${XV%)}" ;; *) XV="" ;; esac # fr
# Every layout Anaconda chose, and its switch shortcut, not only the first one:
# a language whose own layout cannot type Latin letters (ru, bg, el, uk…) gets
# "us" first (user names and passwords are typed in Latin letters) and its own
# layout second. Keeping only the first one left those users without their
# keyboard on the installed system. XL/XV/XO: comma-separated, as XKB wants.
XL=""; XV=""; XO=""
eval "$(python3 - 2>/dev/null <<'KBPY'
import re, shlex
layouts, options = [], []
try:
with open("/root/anaconda-ks.cfg", encoding="utf-8") as fh:
for line in fh:
if line.startswith("keyboard"):
for token in shlex.split(line)[1:]:
name, _, value = token.partition("=")
items = [item.strip() for item in value.split(",") if item.strip()]
if name == "--xlayouts":
layouts = items
elif name == "--switch":
options = items
break
except OSError:
pass
if not layouts:
# No layout in the generated kickstart: the same rule as Anaconda, from
# the installed locale (fr_CH -> ch(fr); ru_RU -> us + ru).
import langtable
locale = ""
try:
with open("/etc/locale.conf", encoding="utf-8") as fh:
for line in fh:
if line.startswith("LANG="):
locale = line.split("=", 1)[1].strip().strip("\"'").split(".")[0]
except OSError:
pass
language, _, territory = locale.partition("_")
if language and territory:
keyboards = langtable.list_keyboards(languageId=language, territoryId=territory)
if keyboards:
layouts = [keyboards[0]]
if not langtable.supports_ascii(keyboards[0].replace(" ", "")):
layouts.insert(0, "us")
pairs = []
for item in layouts:
match = re.match(r"^([\w/-]+)\s*(?:\(\s*([^)]*?)\s*\))?$", item)
if match:
pairs.append((match.group(1), match.group(2) or ""))
if len(pairs) > 1 and not options:
options = ["grp:alt_shift_toggle"]
print("XL=" + shlex.quote(",".join(layout for layout, _ in pairs)))
print("XV=" + shlex.quote(",".join(variant for _, variant in pairs)))
print("XO=" + shlex.quote(",".join(options)))
KBPY
)"
if [ -n "$XL" ]; then
install -d /etc/X11/xorg.conf.d
cat > /etc/X11/xorg.conf.d/00-keyboard.conf <<KBEOF
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "$XL"
Option "XkbVariant" "$XV"
EndSection
KBEOF
{
printf 'Section "InputClass"\n'
printf ' Identifier "system-keyboard"\n'
printf ' MatchIsKeyboard "on"\n'
printf ' Option "XkbLayout" "%s"\n' "$XL"
printf ' Option "XkbVariant" "%s"\n' "$XV"
[ -n "$XO" ] && printf ' Option "XkbOptions" "%s"\n' "$XO"
printf 'EndSection\n'
} > /etc/X11/xorg.conf.d/00-keyboard.conf
echo "[FWS] clavier : $XL ($XV) ${XO:+— bascule $XO}"
fi
FWSLANG="$(. /etc/locale.conf 2>/dev/null; printf '%s' "${LANG:-}")"
@@ -573,7 +619,7 @@ case "$DESK" in
# i3 : session X11 → COMPATIBLE VR (SteamVR ne marche pas sous Wayland).
# xorg-server est requis (SDDM ne le tire pas) ; maim+xclip = captures X11,
# dunst = notifications X11 (équivalent de mako), i3lock = verrouillage.
# fws-vr-setup (Super+Shift+V ou menu) installe les drivers du casque.
# « Pilotes et matériel » installe la base VR et Steam à la demande.
i3) PKGS="i3-wm i3lock xorg-server polybar picom feh rofi kitty dolphin kio-extras udisks2 sddm noto-fonts ttf-nerd-fonts-symbols maim xclip dunst libnotify polkit-gnome network-manager-applet playerctl brightnessctl pipewire pipewire-alsa pipewire-pulse wireplumber pavucontrol bluez bluez-utils blueman"; DM="sddm" ;;
cli|*) PKGS="" ;;
esac
@@ -829,6 +875,20 @@ fi
fws-install-step 76 fws:progress.desktop_config
# Bar labels ({{t:key}} markers) in the installed system's language: waybar,
# polybar and i3 cannot look texts up themselves, so they are written in once.
for _f in waybar-config.json polybar-config.ini i3-config; do
_src="/usr/local/share/fws/$_f"
[ -f "$_src" ] || continue
if LANG="${FWSLANG:-en_US.UTF-8}" /usr/local/bin/fws-i18n --catalog system \
--render "$_src" > "$_src.fws" && [ -s "$_src.fws" ]; then
mv -f "$_src.fws" "$_src"
else
rm -f "$_src.fws"
echo "[FWS] traduction de $_f impossible — libellés laissés en clés"
fi
done
# --- Config Hyprland (si choisi) : clavier + apps + waybar -------------------
# Hyprland (Wayland) NE lit PAS /etc/X11/xorg.conf.d/00-keyboard.conf : sa
# disposition est dans SA config (input { kb_layout }). Sans config il démarre nu
@@ -836,7 +896,7 @@ fws-install-step 76 fws:progress.desktop_config
# clavier XL/XV injecté) dans /etc/skel ET le home de chaque utilisateur déjà
# créé par Anaconda (le %post tourne APRÈS la création de l'utilisateur).
if [ "$DESK" = "hyprland" ] && [ -f /usr/local/share/fws/hyprland.conf.tmpl ]; then
sed -e "s/__KB_LAYOUT__/${XL:-us}/" -e "s/__KB_VARIANT__/${XV}/" \
sed -e "s/__KB_LAYOUT__/${XL:-us}/" -e "s/__KB_VARIANT__/${XV}/" -e "s/__KB_OPTIONS__/${XO}/" \
/usr/local/share/fws/hyprland.conf.tmpl > /tmp/fws-hyprland.conf
install -Dm644 /tmp/fws-hyprland.conf /etc/skel/.config/hypr/hyprland.conf
# Waybar FWS : barre assortie + bouton « ⌨ Raccourcis » (fws-keys,