diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-05 17:09:11 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-05 18:50:09 -0500 |
commit | 56384e572d419a48439a90b9481a715a13a109c8 (patch) | |
tree | fc132badb5cde0ff2e5713d0cdd2725980306120 /src/lib | |
parent | f5663f08d44091ca16c7f53c492c2594202ba7e5 (diff) |
src/lib/: set TEXTDOMAIN differently for internal messages
This allows us to fix the long-standing bug that libremessages forces
TEXTDOMAIN=libretools
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile | 8 | ||||
-rw-r--r-- | src/lib/common.sh.top | 8 | ||||
-rw-r--r-- | src/lib/conf.sh | 4 | ||||
-rwxr-xr-x | src/lib/libreblacklist | 8 | ||||
-rwxr-xr-x | src/lib/librelib | 29 | ||||
-rwxr-xr-x | src/lib/libremessages | 2 | ||||
-rw-r--r-- | src/lib/libremessages.1.ronn | 6 |
7 files changed, 42 insertions, 23 deletions
diff --git a/src/lib/Makefile b/src/lib/Makefile index 4f24ad3..4ed5e4f 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -14,7 +14,13 @@ common.sh: %: %.in %.top Makefile @{ \ cat '$*.top' && \ echo && \ - sed -r -e '/encoding problem/d;/LANG=/d' -e 's/mesg=\$$(.)/mesg="$$(_ "$$\1")"/' '$*.in' && \ + sed -r \ + -e '/encoding problem/d;/LANG=/d' \ + -e 's/mesg=\$$(.)/mesg="$$(_ "$$\1")"/' \ + -e 's/gettext /_l _ /g' \ + -e "s/^(\s+)(msg|error) '/\1_l \2 '/" \ + -e 's|lock\(\)\s*\{|lock()\n{|' \ + '$*.in' && \ echo && \ cat '$*.bottom' && \ :; } > '$@' diff --git a/src/lib/common.sh.top b/src/lib/common.sh.top index 625ea05..9c4ba2e 100644 --- a/src/lib/common.sh.top +++ b/src/lib/common.sh.top @@ -18,11 +18,15 @@ shopt -s extglob if [[ -z ${_INCLUDE_COMMON_SH:-} ]]; then _INCLUDE_COMMON_SH=true -export TEXTDOMAIN='libretools' -export TEXTDOMAINDIR='/usr/share/locale' +[[ -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' "$@" +} diff --git a/src/lib/conf.sh b/src/lib/conf.sh index 0a6fb89..4445bef 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -122,10 +122,10 @@ check_vars() { if [[ -z ${!VAR:-} ]]; then type print &>/dev/null || . libremessages if [[ $(list_files $slug|wc -l) -gt 1 ]]; then - print "Configure '%s' in one of:" "$VAR" + _l print "Configure '%s' in one of:" "$VAR" list_files $slug | sed 's/./ -> &/' else - print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)" + _l print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)" fi ret=1 fi diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist index 5db1a3f..267d32d 100755 --- a/src/lib/libreblacklist +++ b/src/lib/libreblacklist @@ -48,7 +48,7 @@ blacklist-update() ( local remote_blacklist="$BLACKLIST" local local_blacklist="$XDG_CACHE_HOME/libretools/blacklist.txt" - stat_busy "Downloading blacklist of proprietary software packages" + _l stat_busy "Downloading blacklist of proprietary software packages" mkdir -p "${local_blacklist%/*}" if wget -N -q -O "${local_blacklist}.part" "$remote_blacklist" 2>/dev/null; then @@ -58,9 +58,9 @@ blacklist-update() ( stat_done rm "${local_blacklist}.part" if [[ -e "$local_blacklist" ]]; then - warning "Using local copy of blacklist" + _l warning "Using local copy of blacklist" else - error "Download failed, exiting" + _l error "Download failed, exiting" return 1 fi @@ -109,6 +109,8 @@ if [[ "${0##*/}" == libreblacklist ]]; then sed 's/\r/\n/g'<<<"$1"|sed -e '/^$/d' -e 's/^# //' } usage() { + export TEXTDOMAIN='librelib' + export TEXTDOMAINDIR='/usr/share/locale' . $(librelib messages) if [[ $# -eq 0 ]]; then print "Usage: %s [-h] COMMAND [ARGUMENTS]" "${0##*/}" diff --git a/src/lib/librelib b/src/lib/librelib index a58f5d3..3b05e37 100755 --- a/src/lib/librelib +++ b/src/lib/librelib @@ -16,18 +16,31 @@ default_libdir=/usr/lib/libretools -if ! type gettext &>/dev/null; then - gettext() { echo "$@"; } +if type gettext &>/dev/null; then + _() { gettext "$@"; } +else + _() { echo "$@"; } fi +_l() { + TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@" +} + print() { - mesg=$1 + local mesg="$(_ "$1")" shift - printf -- "$(gettext "$mesg")\n" "$@" + printf -- "$mesg\n" "$@" +} + +_html_whitespace_collapse() { + [[ $# == 0 ]] || panic + tr '\n' ' ' | sed -r -e 's/\t/ /g' -e 's/ +/ /g' } prose() { - print "$@" | fmt -su + [[ $# -ge 1 ]] || panic + local mesg="$(_ "$(_html_whitespace_collapse <<<"$1")")"; shift + printf -- "$mesg" "$@" | fmt -u } cmd=${0##*/} @@ -54,11 +67,11 @@ usage() { main() { if [[ $# != 1 ]]; then - usage >&2 + _l usage >&2 return 2 fi if [[ $1 == '-h' ]]; then - usage + _l usage return 0; fi @@ -76,7 +89,7 @@ main() { return 0; fi done - print '%s: could not find library: %s' "$cmd" "$lib" >> /dev/stderr + _l print '%s: could not find library: %s' "$cmd" "$lib" >> /dev/stderr return 1 } diff --git a/src/lib/libremessages b/src/lib/libremessages index c6d08e2..8766578 100755 --- a/src/lib/libremessages +++ b/src/lib/libremessages @@ -36,7 +36,7 @@ ################################################################################ panic() { - echo "$(_ 'panic: malformed call to internal function')" >&2 + echo "$(_l _ 'panic: malformed call to internal function')" >&2 exit 1 } diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn index b91a958..30314c8 100644 --- a/src/lib/libremessages.1.ronn +++ b/src/lib/libremessages.1.ronn @@ -188,12 +188,6 @@ These routines relate to `makepkg`(8). ## BUGS -libremessages sets <TEXTDOMAIN> to `libretools` unconditionally, -making it generally unsuitable for use outside of libretools. If you -override <TEXTDOMAIN> after loading the library, that should work, but -you will also have to provide translations for libremessage's internal -messages (such as "ERROR" or "Warning"). - Generating `.pot` files for the prose functions is a pain. The libretools Makefiles have rules to do it, but it might make sense to pull it into a separate program. |