feat: add bds core, locale updates and safety fixes
This commit is contained in:
50
lib/i18n.sh
Normal file
50
lib/i18n.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
LOCALE_DIRECTORY="${SCRIPT_DIR}/locales"
|
||||
|
||||
load_locale() {
|
||||
case "${LOCALE,,}" in
|
||||
ru*|ru_*)
|
||||
LOCALE="ru"
|
||||
;;
|
||||
en*|en_*)
|
||||
LOCALE="en"
|
||||
;;
|
||||
*)
|
||||
if [[ "${LANGUAGE:-${LANG:-}}" == ru* ]]; then
|
||||
LOCALE="ru"
|
||||
else
|
||||
LOCALE="en"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$LOCALE" in
|
||||
ru)
|
||||
LOCALE_FILE="$LOCALE_DIRECTORY/ru.sh"
|
||||
;;
|
||||
*)
|
||||
LOCALE_FILE="$LOCALE_DIRECTORY/en.sh"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ! -f "$LOCALE_FILE" ]]; then
|
||||
LOCALE="en"
|
||||
LOCALE_FILE="$LOCALE_DIRECTORY/en.sh"
|
||||
fi
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
. "$LOCALE_FILE"
|
||||
}
|
||||
|
||||
t() {
|
||||
local key="$1"
|
||||
shift || true
|
||||
|
||||
local fn="locale_msg_${key}"
|
||||
if declare -F "$fn" >/dev/null 2>&1; then
|
||||
"$fn" "$@"
|
||||
else
|
||||
echo "$key"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user