diff options
author | P. J. McDermott <pjm@nac.net> | 2012-09-04 22:45:51 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-09-04 22:45:51 (EDT) |
commit | 0dff1771f49e419c5db8a1eb27ec97202c98dec5 (patch) | |
tree | a984b56d450664e7c68359c03f9b493e9f0e860d /lib | |
parent | 3a4f616cd7fcbcc18e6cfc4d98d4e595dc682e47 (diff) |
Remove ob_set_locale and add ob_add_text_domain.
Diffstat (limited to 'lib')
-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 } |