# FWS — translations for the FWS shell tools (Bash, sourced). # # . /usr/local/lib/fws/i18n.sh ... # say "$(t [name=value]...)" # # Loads every text of the given namespaces of system-translations.toml with a # single fws-i18n call, in the language of the environment; t then fills the # {placeholders} in Bash. A missing text prints its key, like the Python tools. # Literal braces ({{ }}) are not supported in texts used from shell. declare -gA FWS_T=() eval "$(/usr/local/bin/fws-i18n --catalog system --shell "$@" 2>/dev/null)" || true t() { local text="${FWS_T[$1]-$1}" pair shift for pair in "$@"; do text="${text//"{${pair%%=*}}"/"${pair#*=}"}" done printf '%s' "$text" } # The answers a yes/no prompt accepts: the translated word, its first letter, # the same without accents ("si" for "sí": not every keyboard has them), and # the English ones that every keyboard can type. t_is_yes() { local answer="${1,,}" yes plain yes="$(t common.yes)" yes="${yes,,}" [ -n "$answer" ] || return 1 # C.UTF-8 is built into glibc, so transliteration works even when the # session's locale is not generated; anything else than plain letters # (a non-Latin word comes out as "?" marks) keeps the word as written. plain="$(printf '%s' "$yes" | LC_ALL=C.UTF-8 iconv -f UTF-8 -t ASCII//TRANSLIT 2>/dev/null)" [[ "$plain" =~ ^[a-z]+$ ]] || plain="$yes" case "$answer" in y | yes | "$yes" | "${yes:0:1}" | "$plain" | "${plain:0:1}") return 0 ;; esac return 1 }