summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-03-15 12:42:48 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-03-15 12:42:48 (EDT)
commit1b6bd8504a43316960623ba503001e1647d459ed (patch)
treeee3a903e0472f1f922ebcc81af352832dbe5bf5d
parent8c769f857af83d7ef464e751f69ed8063382ff5b (diff)
_ob_load_internal_text_domain(): New __init function
-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