From 1b6bd8504a43316960623ba503001e1647d459ed Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 15 Mar 2019 12:42:48 -0400 Subject: _ob_load_internal_text_domain(): New __init function --- (limited to 'lib') 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 -- cgit v0.9.1