1#! /bin/sh 2# 3# Copyright (C) 2003, 2005-2007, 2011, 2018-2020 Free Software Foundation, Inc. 4# 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU Lesser General Public License as published by 7# the Free Software Foundation; either version 2.1 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU Lesser General Public License for more details. 14# 15# You should have received a copy of the GNU Lesser General Public License 16# along with this program. If not, see <https://www.gnu.org/licenses/>. 17# 18 19# Find a way to echo strings without interpreting backslash. 20if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then 21 echo='echo' 22else 23 if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then 24 echo='printf %s\n' 25 else 26 echo_func () { 27 cat <<EOT 28$* 29EOT 30 } 31 echo='echo_func' 32 fi 33fi 34 35# This script is primarily a shell function library. In order for 36# ". gettext.sh" to find it, we install it in $PREFIX/bin (that is usually 37# contained in $PATH), rather than in some other location such as 38# $PREFIX/share/sh-scripts or $PREFIX/share/gettext. In order to not violate 39# the Filesystem Hierarchy Standard when doing so, this script is executable. 40# Therefore it needs to support the standard --help and --version. 41if test -z "${ZSH_VERSION+set}"; then 42 # zsh is not POSIX compliant: By default, while ". gettext.sh" is executed, 43 # it sets $0 to "gettext.sh", defeating the purpose of this test. But 44 # fortunately we know that when running under zsh, this script is always 45 # being sourced, not executed, because hardly anyone is crazy enough to 46 # install zsh as /bin/sh. 47 case "$0" in 48 gettext.sh | */gettext.sh | *\\gettext.sh) 49 progname=$0 50 package=@PACKAGE@ 51 version=@VERSION@ 52 # func_usage 53 # outputs to stdout the --help usage message. 54 func_usage () 55 { 56 echo "GNU gettext shell script function library version $version" 57 echo "Usage: . gettext.sh" 58 } 59 # func_version 60 # outputs to stdout the --version message. 61 func_version () 62 { 63 echo "$progname (GNU $package) $version" 64 echo "Copyright (C) 2003-2020 Free Software Foundation, Inc. 65License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html> 66This is free software: you are free to change and redistribute it. 67There is NO WARRANTY, to the extent permitted by law." 68 echo "Written by" "Bruno Haible" 69 } 70 if test $# = 1; then 71 case "$1" in 72 --help | --hel | --he | --h ) 73 func_usage; exit 0 ;; 74 --version | --versio | --versi | --vers | --ver | --ve | --v ) 75 func_version; exit 0 ;; 76 esac 77 fi 78 func_usage 1>&2 79 exit 1 80 ;; 81 esac 82fi 83 84# eval_gettext MSGID 85# looks up the translation of MSGID and substitutes shell variables in the 86# result. 87eval_gettext () { 88 gettext "$1" | (export PATH `envsubst --variables "$1"`; envsubst "$1") 89} 90 91# eval_ngettext MSGID MSGID-PLURAL COUNT 92# looks up the translation of MSGID / MSGID-PLURAL for COUNT and substitutes 93# shell variables in the result. 94eval_ngettext () { 95 ngettext "$1" "$2" "$3" | (export PATH `envsubst --variables "$1 $2"`; envsubst "$1 $2") 96} 97 98# eval_pgettext MSGCTXT MSGID 99# looks up the translation of MSGID in the context MSGCTXT and substitutes 100# shell variables in the result. 101eval_pgettext () { 102 gettext --context="$1" "$2" | (export PATH `envsubst --variables "$2"`; envsubst "$2") 103} 104 105# eval_npgettext MSGCTXT MSGID MSGID-PLURAL COUNT 106# looks up the translation of MSGID / MSGID-PLURAL for COUNT in the context 107# MSGCTXT and substitutes shell variables in the result. 108eval_npgettext () { 109 ngettext --context="$1" "$2" "$3" "$4" | (export PATH `envsubst --variables "$2 $3"`; envsubst "$2 $3") 110} 111 112# Note: This use of envsubst is much safer than using the shell built-in 'eval' 113# would be. 114# 1) The security problem with Chinese translations that happen to use a 115# character such as \xe0\x60 is avoided. 116# 2) The security problem with malevolent translators who put in command lists 117# like "$(...)" or "`...`" is avoided. 118# 3) The translations can only refer to shell variables that are already 119# mentioned in MSGID or MSGID-PLURAL. 120# 121# Note: "export PATH" above is a dummy; this is for the case when 122# `envsubst --variables ...` returns nothing. 123# 124# Note: In eval_ngettext above, "$1 $2" means a string whose variables set is 125# the union of the variables set of "$1" and "$2". 126# 127# Note: The minimal use of backquote above ensures that trailing newlines are 128# not dropped, not from the gettext invocation and not from the value of any 129# shell variable. 130# 131# Note: Field splitting on the `envsubst --variables ...` result is desired, 132# since envsubst outputs the variables, separated by newlines. Pathname 133# wildcard expansion or tilde expansion has no effect here, since the words 134# output by "envsubst --variables ..." consist solely of alphanumeric 135# characters and underscore. 136