diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-15 23:55:21 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-15 23:55:21 (EDT) |
commit | b5aa7a33b9ecdc0175d2f58f131f6f7ce575a61b (patch) | |
tree | b7867a42079d166e8662ac3a2417b17d7b6e265f | |
parent | ac2d2b30da44758f0b58d110596c8e51432bf209 (diff) |
ob_get_msg(): Make sure ob_set_text_domain() is called first
-rw-r--r-- | lib/locale.sh | 9 |
1 files changed, 8 insertions, 1 deletions
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 |