diff options
Diffstat (limited to 'lib/locale.sh')
-rw-r--r-- | lib/locale.sh | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/lib/locale.sh b/lib/locale.sh index 7cc1635..203faba 100644 --- a/lib/locale.sh +++ b/lib/locale.sh @@ -20,67 +20,64 @@ [ -n "${_OB_LOCALE_SM}" ] && return 0 _OB_LOCALE_SM='true' +. '@@LIBOPKBUILD@@/output.sm' + _OB_DEFAULT_LOCALE='en_US' -ob_set_locale() +ob_add_text_domain() { - _obsl_locale= - _obsl_domain= + _obatd_domain= if [ ${#} -eq 1 ]; then - _obsl_locale= - _obsl_domain="${1}" - elif [ ${#} -eq 2 ]; then - _obsl_locale="${1}" - _obsl_domain="${2}" + _obatd_domain="${1}" else - unset _obsl_locale _obsl_domain + unset _obatd_domain return 125 fi - # Detect the system locale. - # The test command's -z option doesn't work here? - if [ ${#_obsl_locale} -eq 0 ]; then + # Make sure LC_MESSAGES is set. + if [ -z "${LC_MESSAGES}" ]; then if [ -n "${LC_ALL}" ]; then - _obsl_locale="${LC_ALL}" - elif [ -n "${LC_MESSAGES}" ]; then - _obsl_locale="${LC_MESSAGES}" + LC_MESSAGES="${LC_ALL}" elif [ -n "${LANG}" ]; then - _obsl_locale="${LANG}" + LC_MESSAGES="${LANG}" else - _obsl_locale="${_OB_DEFAULT_LOCALE}" + LC_MESSAGES="${_OB_DEFAULT_LOCALE}" fi fi - # Try to load the locale. - if ! _ob_try_load_locale "${_locale%.*}" "${obsl_domain}"; then - if ! _ob_try_load_locale "${_locale%_*}" "${_obsl_domain}"; then - if ! _ob_try_load_locale "${_OB_DEFAULT_LOCALE}" \ - "${_obsl_domain}"; then - printf 'Error: cannot load locale file\n' - unset _obsl_locale _obsl_domain + # TODO: Exit early if domain's messages have already been loaded. + + # Try to load the messages. + if ! _ob_try_load_messages "${LC_MESSAGES%.*}" "${obsl_domain}"; then + if ! _ob_try_load_messages "${LC_MESSAGES%_*}" "${_obatd_domain}"; then + if ! _ob_try_load_messages "${_OB_DEFAULT_LOCALE}" \ + "${_obatd_domain}"; then + ob_warn 'Cannot load messages in "%s" domain.' \ + "${_obatd_domain}" + unset _obatd_domain return 1 fi fi fi - unset _obsl_locale _obsl_domain + unset _obatd_domain return 0 } -_ob_try_load_locale() +_ob_try_load_messages() { - _obtll_locale="${1}" - _obtll_domain="${2}" - _obtll_ms="@@LOCALEDIR@@/${_obtll_locale}/LC_MESSAGES/${_obtll_domain}.ms" + _obtlm_locale="${1}" + _obtlm_domain="${2}" + _obtlm_ms="@@LOCALEDIR@@/${_obtlm_locale}/LC_MESSAGES/${_obtlm_domain}.ms" - if [ -f "${_obtll_ms}" ]; then - . "${_obtll_ms}" + if [ -f "${_obtlm_ms}" ]; then + . "${_obtlm_ms}" else - unset _obtll_locale _obtll_domain _obtll_ms + unset _obtlm_locale _obtlm_domain _obtlm_ms return 1 fi - unset _obtll_locale _obtll_domain _obtll_ms + unset _obtlm_locale _obtlm_domain _obtlm_ms return 0 } |