summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/locale.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/locale.sh b/lib/locale.sh
index 54bb211..0fb37ef 100644
--- a/lib/locale.sh
+++ b/lib/locale.sh
@@ -138,3 +138,43 @@ _ob_get_msg()
return 0
}
+
+_ob_try_load_internal_messages()
+{
+ local locale="${1}"
+ shift 1 || _ob_abort
+ local ms=
+
+ _OB_LOCALE_PATH="${LOCALEDIR}/%s/LC_MESSAGES/%s.ms"
+ if [ x"${OB_BUILDDIR:+set}" = 'xset' ]; then # Env var set and not null
+ ms="${OB_BUILDDIR}"
+ ms="${ms}/locale/${locale}/${_OB_INTERNAL_TEXT_DOMAIN}.ms"
+ else
+ ms="${LOCALEDIR}"
+ ms="${ms}/${locale}/LC_MESSAGES/${_OB_INTERNAL_TEXT_DOMAIN}.ms"
+ fi
+
+ eval "$(cat "${ms}" 2>/dev/null)" || return 1
+ return 0
+}
+
+_ob_load_internal_text_domain()
+{
+ # Make sure LC_MESSAGES is set.
+ if [ -z "${LC_MESSAGES}" ]; then
+ if [ -n "${LC_ALL}" ]; then
+ LC_MESSAGES="${LC_ALL}"
+ elif [ -n "${LANG}" ]; then
+ LC_MESSAGES="${LANG}"
+ else
+ LC_MESSAGES="${_OB_DEFAULT_LOCALE}"
+ fi
+ fi
+
+ # Try to load the messages.
+ if ! _ob_try_load_internal_messages "${LC_MESSAGES%.*}"; then
+ printf '%s: Error: Failed to load locale messages\n' \
+ "${0##*/}" >&2
+ fi
+}
+__init _ob_load_internal_text_domain