home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / gettext.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2006-08-18  |  4.4 KB  |  122 lines

  1. #! /bin/sh
  2. #
  3. # Copyright (C) 2003, 2005 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 General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # 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 General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. #
  19.  
  20. # Find a way to echo strings without interpreting backslash.
  21. if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
  22.   echo='echo'
  23. else
  24.   if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
  25.     echo='printf %s\n'
  26.   else
  27.     echo_func () {
  28.       cat <<EOT
  29. $*
  30. EOT
  31.     }
  32.     echo='echo_func'
  33.   fi
  34. fi
  35.  
  36. # This script is primarily a shell function library. In order for
  37. # ". gettext.sh" to find it, we install it in $PREFIX/bin (that is usually
  38. # contained in $PATH), rather than in some other location such as
  39. # $PREFIX/share/sh-scripts or $PREFIX/share/gettext. In order to not violate
  40. # the Filesystem Hierarchy Standard when doing so, this script is executable.
  41. # Therefore it needs to support the standard --help and --version.
  42. if test -z "$ZSH_VERSION"; then
  43.   # zsh is not POSIX compliant: By default, while ". gettext.sh" is executed,
  44.   # it sets $0 to "gettext.sh", defeating the purpose of this test. But
  45.   # fortunately we know that when running under zsh, this script is always
  46.   # being sourced, not executed, because hardly anyone is crazy enough to
  47.   # install zsh as /bin/sh.
  48. case "$0" in
  49.   gettext.sh | */gettext.sh | *\gettext.sh)
  50.     progname=$0
  51.     package=gettext-runtime
  52.     version=0.14.6
  53.     # func_usage
  54.     # outputs to stdout the --help usage message.
  55.     func_usage ()
  56.     {
  57.       echo "GNU gettext shell script function library version $version"
  58.       echo "Usage: . gettext.sh"
  59.     }
  60.     # func_version
  61.     # outputs to stdout the --version message.
  62.     func_version ()
  63.     {
  64.       echo "$progname (GNU $package) $version"
  65.       echo "Copyright (C) 2003-2005 Free Software Foundation, Inc.
  66. This is free software; see the source for copying conditions.  There is NO
  67. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
  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
  82. fi
  83.  
  84. # eval_gettext MSGID
  85. # looks up the translation of MSGID and substitutes shell variables in the
  86. # result.
  87. eval_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.
  94. eval_ngettext () {
  95.   ngettext "$1" "$2" "$3" | (export PATH `envsubst --variables "$1 $2"`; envsubst "$1 $2")
  96. }
  97.  
  98. # Note: This use of envsubst is much safer than using the shell built-in 'eval'
  99. # would be.
  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.
  106. #
  107. # Note: "export PATH" above is a dummy; this is for the case when
  108. # `envsubst --variables ...` returns nothing.
  109. #
  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".
  112. #
  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
  115. # shell variable.
  116. #
  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.
  122.