3 # Copyright (C) 2003, 2005-2007, 2011 Free Software Foundation, Inc.
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.
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.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Find a way to echo strings without interpreting backslash.
20 if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
23 if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
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.
41 if 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.
48 gettext.sh | */gettext.sh | *\\gettext.sh)
53 # outputs to stdout the --help usage message.
56 echo "GNU gettext shell script function library version $version"
57 echo "Usage: . gettext.sh"
60 # outputs to stdout the --version message.
63 echo "$progname (GNU $package) $version"
64 echo "Copyright (C) 2003-2007 Free Software Foundation, Inc.
65 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
66 This is free software: you are free to change and redistribute it.
67 There is NO WARRANTY, to the extent permitted by law."
68 echo "Written by" "Bruno Haible"
72 --help | --hel | --he | --h )
74 --version | --versio | --versi | --vers | --ver | --ve | --v )
75 func_version; exit 0 ;;
85 # looks up the translation of MSGID and substitutes shell variables in the
88 gettext "$1" | (export PATH `envsubst --variables "$1"`; envsubst "$1")
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.
95 ngettext "$1" "$2" "$3" | (export PATH `envsubst --variables "$1 $2"`; envsubst "$1 $2")
98 # Note: This use of envsubst is much safer than using the shell built-in 'eval'
100 # 1) The security problem with Chinese translations that happen to use a
101 # character such as \xe0\x60 is avoided.
102 # 2) The security problem with malevolent translators who put in command lists
103 # like "$(...)" or "`...`" is avoided.
104 # 3) The translations can only refer to shell variables that are already
105 # mentioned in MSGID or MSGID-PLURAL.
107 # Note: "export PATH" above is a dummy; this is for the case when
108 # `envsubst --variables ...` returns nothing.
110 # Note: In eval_ngettext above, "$1 $2" means a string whose variables set is
111 # the union of the variables set of "$1" and "$2".
113 # Note: The minimal use of backquote above ensures that trailing newlines are
114 # not dropped, not from the gettext invocation and not from the value of any
117 # Note: Field splitting on the `envsubst --variables ...` result is desired,
118 # since envsubst outputs the variables, separated by newlines. Pathname
119 # wildcard expansion or tilde expansion has no effect here, since the words
120 # output by "envsubst --variables ..." consist solely of alphanumeric
121 # characters and underscore.