#!/usr/bin/env bash # i18n.sh — UI language + regional locale for taler-monitoring console + HTML # # UI language (mon badges / sticky chrome): # TALER_MON_LANG=en|fr|de # TALER_MON_LANG_SET=1 → explicit (--lang); do not override. # Auto (SET≠1): TALER_DOMAIN_LANG from domains.conf `lang` column. # de is supported but never a stock profile default (no domains.conf row uses lang=de). # # Regional locale (l10n defaults, BCP 47 — not the same as UI lang): # TALER_MON_LOCALE / TALER_DOMAIN_LOCALE e.g. fr-CH, de-CH # From domains.conf `locale` column (fr-CH for FP, de-CH for others). # Aliases ch-FR / ch-DE accepted and normalized to fr-CH / de-CH. # # domains.conf is the source of truth for both lang and locale. : "${TALER_MON_LANG:=}" : "${TALER_MON_LANG_SET:=0}" : "${TALER_DOMAIN_LANG:=}" : "${TALER_DOMAIN_LOCALE:=}" : "${TALER_MON_LOCALE:=}" i18n_init() { # Only TALER_MON_LANG_SET=1 is "explicit". Do not promote non-empty TALER_MON_LANG # to SET=1 — env files often ship LANG=en for the default GOA workstation. if [ "${TALER_MON_LANG_SET:-0}" != "1" ]; then if [ -n "${TALER_DOMAIN_LANG:-}" ]; then TALER_MON_LANG="$TALER_DOMAIN_LANG" else case "${TALER_DOMAIN:-}" in *lefrancpaysan*|*francpaysan*) TALER_MON_LANG=fr ;; *) if [ -z "${TALER_MON_LANG:-}" ]; then TALER_MON_LANG=en fi ;; esac fi fi case "${TALER_MON_LANG}" in fr|FR|fra|french) TALER_MON_LANG=fr ;; de|DE|deu|ger|german|deutsch) TALER_MON_LANG=de ;; *) TALER_MON_LANG=en ;; esac # Regional locale from profile (or FP/other fallback) if [ -n "${TALER_DOMAIN_LOCALE:-}" ]; then TALER_MON_LOCALE="$TALER_DOMAIN_LOCALE" elif [ -z "${TALER_MON_LOCALE:-}" ]; then case "${TALER_DOMAIN:-}" in *lefrancpaysan*|*francpaysan*) TALER_MON_LOCALE=fr-CH ;; *) TALER_MON_LOCALE=de-CH ;; esac fi # normalize aliases case "$(printf '%s' "$TALER_MON_LOCALE" | tr '[:upper:]' '[:lower:]' | tr '_' '-')" in fr-ch|ch-fr) TALER_MON_LOCALE=fr-CH ;; de-ch|ch-de) TALER_MON_LOCALE=de-CH ;; en-ch|ch-en) TALER_MON_LOCALE=en-CH ;; esac export TALER_MON_LANG export TALER_MON_LANG_SET export TALER_DOMAIN_LANG export TALER_DOMAIN_LOCALE export TALER_MON_LOCALE } i18n_tag() { local t="$1" case "${TALER_MON_LANG:-en}" in fr) case "$t" in OK) printf 'OK' ;; ERROR) printf 'ERREUR' ;; WARN) printf 'AVERT' ;; INFO) printf 'INFO' ;; BLOCKER) printf 'BLOCAGE' ;; BLOCK) printf 'BLOC' ;; SUMMARY) printf 'RESUME' ;; PROG|PROGRESS) printf 'PROG' ;; *) printf '%s' "$t" ;; esac ;; de) case "$t" in OK) printf 'OK' ;; ERROR) printf 'FEHLER' ;; WARN) printf 'WARNUNG' ;; INFO) printf 'INFO' ;; BLOCKER) printf 'BLOCKER' ;; BLOCK) printf 'BLOCK' ;; SUMMARY) printf 'ZUSAMMENFASSUNG' ;; PROG|PROGRESS) printf 'PROG' ;; *) printf '%s' "$t" ;; esac ;; *) printf '%s' "$t" ;; esac } i18n_text() { local s="$*" [ -z "$s" ] && { printf '%s' "$s"; return 0; } case "${TALER_MON_LANG:-en}" in fr) case "$s" in "numbered checks this run:") printf 'controles numerotes de cette execution :' ;; "numbered checks:") printf 'controles numerotes :' ;; "(global done/total)") printf '(fait/total global)' ;; "global checks:") printf 'controles globaux :' ;; "failed — see list above"|"failed - see list above") printf 'echec — voir la liste ci-dessus' ;; "BLOCKERS · pay/withdraw cannot finish") printf 'BLOCAGES · paiement/retrait impossible' ;; "BLOCKERS (pay/withdraw cannot finish)") printf 'BLOCAGES (paiement/retrait impossible)' ;; "ERRORS · failed checks") printf 'ERREURS · controles en echec' ;; "ERRORS (failed checks)") printf 'ERREURS (controles en echec)' ;; "pay/withdraw cannot finish") printf 'paiement/retrait impossible a terminer' ;; "SUMMARY") printf 'RESUME' ;; "totals:") printf 'totaux :' ;; "all clear") printf 'tout est clair' ;; "warnings only (no hard fail)") printf 'avertissements seulement (pas d'\''echec dur)' ;; "monitoring") printf 'surveillance' ;; "surface") printf 'surface' ;; "aptdeploy") printf 'aptdeploy' ;; "container") printf 'conteneur' ;; "disk") printf 'disque' ;; "package") printf 'paquet' ;; "version") printf 'version' ;; "reachability") printf 'accessibilite' ;; "server-header") printf 'en-tete Server' ;; "inventory") printf 'inventaire' ;; "flags") printf 'options' ;; "target domain") printf 'domaine cible' ;; "currency") printf 'devise' ;; "phases") printf 'phases' ;; "access") printf 'acces' ;; *) local out="$s" out=${out//shared library missing/bibliotheque partagee manquante} out=${out//not active/non actif} out=${out//does not resolve/ne resout pas} out=${out//from Server header/depuis en-tete Server} out=${out//public HTTPS/HTTPS public} out=${out//no SSH/sans SSH} out=${out//failed — see list above/echec — voir la liste ci-dessus} printf '%s' "$out" ;; esac ;; de) case "$s" in "numbered checks this run:") printf 'Nummerierte Pruefungen dieser Ausfuehrung :' ;; "numbered checks:") printf 'Nummerierte Pruefungen :' ;; "(global done/total)") printf '(fertig/gesamt global)' ;; "global checks:") printf 'Globale Pruefungen :' ;; "failed — see list above"|"failed - see list above") printf 'fehlgeschlagen — siehe Liste oben' ;; "BLOCKERS · pay/withdraw cannot finish") printf 'BLOCKER · Zahlung/Abhebung nicht moeglich' ;; "BLOCKERS (pay/withdraw cannot finish)") printf 'BLOCKER (Zahlung/Abhebung nicht moeglich)' ;; "ERRORS · failed checks") printf 'FEHLER · fehlgeschlagene Pruefungen' ;; "ERRORS (failed checks)") printf 'FEHLER (fehlgeschlagene Pruefungen)' ;; "pay/withdraw cannot finish") printf 'Zahlung/Abhebung kann nicht beendet werden' ;; "SUMMARY") printf 'ZUSAMMENFASSUNG' ;; "totals:") printf 'Summen :' ;; "all clear") printf 'alles in Ordnung' ;; "warnings only (no hard fail)") printf 'nur Warnungen (kein harter Fehler)' ;; "monitoring") printf 'Ueberwachung' ;; "surface") printf 'Surface' ;; "aptdeploy") printf 'aptdeploy' ;; "container") printf 'Container' ;; "disk") printf 'Disk' ;; "package") printf 'Paket' ;; "version") printf 'Version' ;; "reachability") printf 'Erreichbarkeit' ;; "server-header") printf 'Server-Header' ;; "inventory") printf 'Inventar' ;; "flags") printf 'Flags' ;; "target domain") printf 'Zieldomaene' ;; "currency") printf 'Waehrung' ;; "phases") printf 'Phasen' ;; "access") printf 'Zugang' ;; *) local outd="$s" outd=${outd//shared library missing/gemeinsame Bibliothek fehlt} outd=${outd//not active/nicht aktiv} outd=${outd//does not resolve/loest nicht auf} outd=${outd//from Server header/aus Server-Header} outd=${outd//public HTTPS/oeffentliches HTTPS} outd=${outd//no SSH/ohne SSH} outd=${outd//failed — see list above/fehlgeschlagen — siehe Liste oben} printf '%s' "$outd" ;; esac ;; *) printf '%s' "$s" ;; esac }