summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/locale.sh68
1 files changed, 46 insertions, 22 deletions
diff --git a/lib/locale.sh b/lib/locale.sh
index 6e57fc3..06bd60a 100644
--- a/lib/locale.sh
+++ b/lib/locale.sh
@@ -1,4 +1,4 @@
-# opkhelper
+# opkbuild
# lib/locale
# Locale functions.
#
@@ -17,41 +17,65 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-[ -n "${_OH_LOCALE_SH}" ] && return 0
-_OH_LOCALE_SH=true
+[ -n "${_OB_LOCALE_SM}" ] && return 0
+_OB_LOCALE_SM='true'
-. @@LOCALEDIR@@/en_US
+_OB_DEFAULT_LOCALE='en_US'
-oh_locale_set()
+ob_set_locale()
{
- _locale="${1}"
+ _obsl_locale=
+ _obsl_domain=
+
+ if [ ${#} -eq 1 ]; then
+ _obsl_locale=
+ _obsl_domain="${1}"
+ elif [ ${#} -eq 2 ]; then
+ _obsl_locale="${1}"
+ _obsl_domain="${2}"
+ else
+ return 125
+ fi
# Detect the system locale.
# The test command's -z option doesn't work here?
- if [ ${#_locale} -eq 0 ]; then
+ if [ ${#_obsl_locale} -eq 0 ]; then
if [ -n "${LC_ALL}" ]; then
- _locale="${LC_ALL}"
+ _obsl_locale="${LC_ALL}"
elif [ -n "${LC_MESSAGES}" ]; then
- _locale="${LC_MESSAGES}"
+ _obsl_locale="${LC_MESSAGES}"
elif [ -n "${LANG}" ]; then
- _locale="${LANG}"
+ _obsl_locale="${LANG}"
else
- _locale='en_US'
+ _obsl_locale="${_OB_DEFAULT_LOCALE}"
fi
fi
# Try to load the locale.
- if [ -f "@@LOCALEDIR@@/${_locale%.*}" ]; then
- LC_ALL="${_locale%.*}"
- LC_MESSAGES="${LC_ALL}"
- . "@@LOCALEDIR@@/${LC_MESSAGES}"
- elif [ -f "@@LOCALEDIR@@/${_locale%_*}" ]; then
- LC_ALL="${_locale%_*}"
- LC_MESSAGES="${LC_ALL}"
- . "@@LOCALEDIR@@/${LC_MESSAGES}"
+ 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'
+ return 1
+ fi
+ fi
+ fi
+
+ return 0
+}
+
+_ob_try_load_locale()
+{
+ _obtll_locale="${1}"
+ _obtll_domain="${2}"
+ _obtll_ms="@@LOCALEDIR@@/${_obtll_locale}/LC_MESSAGES/${_obtll_domain}.ms"
+
+ if [ -f "${_obtll_ms}" ]; then
+ . "${_obtll_ms}"
else
- LC_ALL=en_US
- LC_MESSAGES="${LC_ALL}"
- . "@@LOCALEDIR@@/${LC_MESSAGES}"
+ return 1
fi
+
+ return 0
}