Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/common.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2017-02-15 14:03:57 -0500
committerLuke Shumaker <lukeshu@parabola.nu>2017-02-15 14:03:57 -0500
commit10820f2701f1fe43ea32d72c88b6a70dace09b76 (patch)
tree8dd6d449a8bf8b1681e18916f13c9b6b6fdc59c7 /lib/common.sh
parent880ae81d3c485a54c744cb75f3faa4adf8cea802 (diff)
lib/common.sh: Internationalize.
Diffstat (limited to 'lib/common.sh')
-rw-r--r--lib/common.sh36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 33f9552..89cd257 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -6,8 +6,18 @@
[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0
_INCLUDE_COMMON_SH=true
-# Avoid any encoding problems
-export LANG=C
+[[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools'
+[[ -n ${TEXTDOMAINDIR:-} ]] || export TEXTDOMAINDIR='/usr/share/locale'
+
+if type gettext &>/dev/null; then
+ _() { gettext "$@"; }
+else
+ _() { echo "$@"; }
+fi
+
+_l() {
+ TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@"
+}
shopt -s extglob
@@ -34,37 +44,37 @@ fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
plain() {
- local mesg=$1; shift
+ local mesg="$(_ "$1")"; shift
printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg() {
- local mesg=$1; shift
+ local mesg="$(_ "$1")"; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
msg2() {
- local mesg=$1; shift
+ local mesg="$(_ "$1")"; shift
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
warning() {
- local mesg=$1; shift
- printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ local mesg="$(_ "$1")"; shift
+ printf "${YELLOW}==> $(_l _ "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
error() {
- local mesg=$1; shift
- printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ local mesg="$(_ "$1")"; shift
+ printf "${RED}==> $(_l _ "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
stat_busy() {
- local mesg=$1; shift
+ local mesg="$(_ "$1")"; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2
}
stat_done() {
- printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2
+ printf "${BOLD}$(_l _ "done")${ALL_OFF}\n" >&2
}
_setup_workdir=false
@@ -83,7 +93,7 @@ cleanup() {
}
abort() {
- error 'Aborting...'
+ _l error 'Aborting...'
cleanup 255
}
@@ -261,7 +271,7 @@ find_cached_package() {
return 0
;;
*)
- error 'Multiple packages found:'
+ _l error 'Multiple packages found:'
printf '\t%s\n' "${results[@]}" >&2
return 1
esac