From b5aa7a33b9ecdc0175d2f58f131f6f7ce575a61b Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 15 Mar 2019 23:55:21 -0400 Subject: ob_get_msg(): Make sure ob_set_text_domain() is called first --- (limited to 'lib') diff --git a/lib/locale.sh b/lib/locale.sh index bcc6b1e..2ade95c 100644 --- a/lib/locale.sh +++ b/lib/locale.sh @@ -21,6 +21,7 @@ _OB_DEFAULT_LOCALE='en_US' _OB_INTERNAL_TEXT_DOMAIN="libopkbuild_${LIBOPKBUILD_SHSOVERSION}" _ob_text_domain= _ob_builddir= +_ob_msgs_loaded=false ## @brief Get the current message domain ## @details \fBob_get_text_domain\fP() prints the currently loaded message @@ -94,12 +95,14 @@ ob_set_text_domain() fi fi + _ob_msgs_loaded=true return 0 } ## @brief Get a message from the current message domain ## @details \fBob_get_msg\fP() prints a message, identified by a message ID, -## from the currently loaded message catalog. +## from the currently loaded message catalog. +## \fBob_set_text_domain\fP() must be called first. ## @operand msgid req The ID of the message to print ## @return Returns 0 on success. ## @stdout Prints the requested message from the current message domain. @@ -109,6 +112,10 @@ ob_get_msg() local msgid="${1}" shift 1 || _ob_abort + if ! ${_ob_msgs_loaded}; then + printf '%s: Error: No text domain set\n' "${0##*/}" >&2 + _ob_abort + fi eval "printf '%s' \"\${msg_${_ob_text_domain}_${msgid}}\"" return 0 -- cgit v0.9.1