diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-09-11 10:19:02 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-09-11 15:43:36 -0400 |
commit | 8443cad920a59918069dbee3891b4b9595c528a3 (patch) | |
tree | 944abe452a5db85b045d422a39088bca7094a5cb /src | |
parent | 4b9f4323abfaa0f4030cc29aed97e0716f9c5852 (diff) |
librelib: Internationalize (actually use the internationalization stuff)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Makefile | 12 | ||||
-rw-r--r-- | src/lib/conf.sh | 11 | ||||
-rwxr-xr-x | src/lib/libreblacklist | 46 | ||||
-rwxr-xr-x | src/lib/librelib | 30 |
4 files changed, 63 insertions, 36 deletions
diff --git a/src/lib/Makefile b/src/lib/Makefile index 255bc05..45fd330 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -16,3 +16,15 @@ common.sh: %: %.in %.top Makefile echo && \ cat '$*.bottom' && \ :; } > '$@' + +# Translate ########################################################## + +pot: libreblacklist.pot common.sh.pot librelib.pot + +libreblacklist.pot: libreblacklist + { \ + sed -n '/^# Usage:/,/()/{ /^#/ { =; p; } }' $< | sed -r -e 's/^# (.*)/msgid "\1"/' -e 's/^[0-9]*$$/#. embedded usage text\n#: $<:&/'; \ + sed -rn '/print /{ =; s/\s*print "([^"]*)".*/msgid "\1"/p; }' $< | sed 's/^[0-9]*$$/#. print\n#: $<:&/' ; \ + } | sed 's/^msgid .*/&\nmsgstr ""\n/' > $@ +common.sh.pot: common.sh + xgettext --omit-header -i --from-code=UTF-8 -L shell -o $@ $< diff --git a/src/lib/conf.sh b/src/lib/conf.sh index 8b855fe..ea4f15e 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -106,21 +106,24 @@ load_files() { # If not, it prints a message saying to set them in the configuration file(s) # for $slug. check_vars() { - local slug=$1 - shift + local slug=$1; shift + local ret=0 + local VAR for VAR in "$@"; do if [[ -z ${!VAR:-} ]]; then + type print &>/dev/null || . libremessages if [[ $(list_files $slug|wc -l) -gt 1 ]]; then - echo "Configure '$VAR' in one of:" + print "Configure '%s' in one of:" "$VAR" list_files $slug | sed 's/./ -> &/' else - echo "Configure '$VAR' in $(list_files $slug)" + print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)" fi ret=1 fi done >&2 + if [[ $ret != 0 ]]; then return 1 fi diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist index fb8b43a..bbba1ce 100755 --- a/src/lib/libreblacklist +++ b/src/lib/libreblacklist @@ -16,18 +16,17 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # make sure XDG_CACHE_HOME is set -. $(librelib conf.sh) +. $(librelib conf) # Usage: blacklist-normalize <$file -# Normalizes the syntax of the blacklist on stdin +# Normalizes the syntax of the blacklist on stdin. blacklist-normalize() { sed -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/' } # Usage: blacklist-cat # Prints the blacklist. -# Uses the chache, but downloads it if it doesn't exist. Also normalizes the -# blacklist for easier parsing. +# Uses the cache, but downloads it if it doesn't exist. Also normalizes the blacklist for easier parsing. blacklist-cat() { local file="$XDG_CACHE_HOME/libretools/blacklist.txt" if ! [[ -e $file ]]; then @@ -38,7 +37,7 @@ blacklist-cat() { } # Usage: blacklist-update -# Updates (or creates) the cached copy of the blacklist +# Updates (or creates) the cached copy of the blacklist. blacklist-update() ( . libremessages load_files libretools || return 1 @@ -95,33 +94,38 @@ blacklist-get-reason() { if [[ "${0##*/}" == libreblacklist ]]; then usage-outside() { - sed -n '/^# Usage:/,/()/p' $0 | + sed -n '/^# Usage:/,/()/p' "$0" | tr '\n' '\r' | sed 's/\s*()\s*[{(]/\n/g' } + # The output format of this is: + # - The first line is "Usage:" + # - The second line is a brief description + # - The last line is the command name (prefixed with "blacklist-") + # - The in-between lines are the extended description. usage-inside() { - sed 's/\r/\n/g'<<<"$1"|sed '/^$/d' + sed 's/\r/\n/g'<<<"$1"|sed -e '/^$/d' -e 's/^# //' } usage() { + . $(librelib messages) if [[ $# -eq 0 ]]; then - printf "Usage: %s [-h] COMMAND [ARGUMENTS]\n" "${0##*/}" - echo "Tool for working with the nonfree software blacklist" + print "Usage: %s [-h] COMMAND [ARGUMENTS]" "${0##*/}" + print "Tool for working with the nonfree software blacklist" echo - echo "Commands:" + print "Commands:" usage-outside | while read -r sec; do sec="$(usage-inside "$sec")" - <<<"$sec" sed -n \ - -e 's/blacklist-//g' \ - -e 's/^# //' \ - -e '2p;$p' | - tac|tr '\n' '\t' - echo - done|column -t -s"$(printf '\t')"|sed 's/^/ /' + cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') + desc="$(_ "$(sed -n 2p <<<"$sec")")" + flag "$cmd" "${desc//blacklist-/${0##*/} }" + done else usage-outside | while read -r sec; do sec="$(usage-inside "$sec")" - cmd=$(<<<"$sec" sed -n 's/.*blacklist[ -]//;$p') + cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') if [[ "$cmd" == "$1" ]]; then - <<<"$sec" sed -n \ - -e "s/blacklist-/${0##*/} /g" \ - -e 's/^# //p' + <<<"$sec" sed '$d' | + while read -r line; do _ "$line"; done | + sed "s/blacklist-/${0##*/} /g" | + fmt -us + return 0 fi done fi diff --git a/src/lib/librelib b/src/lib/librelib index dc4969f..c5578a2 100755 --- a/src/lib/librelib +++ b/src/lib/librelib @@ -16,9 +16,18 @@ default_libdir=/usr/lib/libretools +if ! type gettext &>/dev/null; then + gettext() { echo "$@"; } +fi + print() { - fmt=$1; shift - printf -- "$fmt\n" "$@" + mesg=$1 + shift + printf -- "$(gettext "$mesg")\n" "$@" +} + +prose() { + print "$@" | fmt -su } cmd=${0##*/} @@ -27,17 +36,16 @@ usage() { print 'Usage: . $(%s LIBRARY)' "$cmd" print "Finds a shell library file" echo - print "While some libraries can be sourced just by their name because" - print "they are installed in PATH (like libremessages), some are not" - print "installed there (like conf.sh), so a path must be given." - print "Hardcoding that path is the way of the dark side." + prose "While some libraries can be sourced just by their name because + they are installed in PATH (like libremessages), some are not + installed there (like conf.sh), so a path must be given. + Hardcoding that path is the way of the dark side." echo - print "By default, it looks for the files in '%s'," "$default_libdir" - print "but this can be changed with the environmental variable" - print "LIBRETOOLS_LIBDIR." + prose 'By default, it looks for the files in `%s`, but this can be + changed with the environmental variable LIBRETOOLS_LIBDIR.' "$default_libdir" echo print "Example usage:" - print ' . $(librelib conf.sh)' + printf ' . $(%s conf.sh)\n' "$cmd" } main() { @@ -64,7 +72,7 @@ main() { return 0; fi done - printf 'librelib: could not find library `%s`\n' "$lib" >> /dev/stderr + print '%s: could not find library: %s' "$cmd" "$lib" >> /dev/stderr return 1 } |