Files
mcma-bootstrap/lib/i18n.sh
T
Senko-san 1b251869c4 initial
2026-06-08 12:49:45 +03:00

31 lines
849 B
Bash

# i18n loader. Exposes the MSG associative array and the `t` accessor.
#
# i18n_load en # populate MSG from i18n/en.sh
# t step_db # echo MSG[step_db]
# t pull_images foo # printf MSG[pull_images] with args (for %s placeholders)
#
# Strings live in i18n/<locale>.sh; logic never hardcodes user-facing text.
declare -A MSG
i18n_load() {
local locale="$1"
local file="${BOOTSTRAP_DIR}/i18n/${locale}.sh"
[[ -f "$file" ]] || file="${BOOTSTRAP_DIR}/i18n/en.sh"
# shellcheck source=/dev/null
source "$file"
LOCALE="$locale"
}
# t KEY [printf-args...] — resolve a string, optionally formatting placeholders.
t() {
local key="$1"; shift
local s="${MSG[$key]:-$key}"
if (($# > 0)); then
# shellcheck disable=SC2059
printf "$s" "$@"
else
printf '%s' "$s"
fi
}