git-sh-i18n.shon commit Fourth batch (bc12974)
   1# This shell library is Git's interface to gettext.sh. See po/README
   2# for usage instructions.
   3#
   4# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
   5#
   6
   7# Export the TEXTDOMAIN* data that we need for Git
   8TEXTDOMAIN=git
   9export TEXTDOMAIN
  10if test -z "$GIT_TEXTDOMAINDIR"
  11then
  12        TEXTDOMAINDIR="@@LOCALEDIR@@"
  13else
  14        TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
  15fi
  16export TEXTDOMAINDIR
  17
  18# First decide what scheme to use...
  19GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
  20if test -n "$GIT_TEST_GETTEXT_POISON" &&
  21            git env--helper --type=bool --default=0 --exit-code \
  22                GIT_TEST_GETTEXT_POISON
  23then
  24        GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
  25elif test -n "@@USE_GETTEXT_SCHEME@@"
  26then
  27        GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
  28elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
  29then
  30        : no probing necessary
  31elif type gettext.sh >/dev/null 2>&1
  32then
  33        # GNU libintl's gettext.sh
  34        GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
  35elif test "$(gettext -h 2>&1)" = "-h"
  36then
  37        # gettext binary exists but no gettext.sh. likely to be a gettext
  38        # binary on a Solaris or something that is not GNU libintl and
  39        # lack eval_gettext.
  40        GIT_INTERNAL_GETTEXT_SH_SCHEME=gettext_without_eval_gettext
  41fi
  42export GIT_INTERNAL_GETTEXT_SH_SCHEME
  43
  44# ... and then follow that decision.
  45case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
  46gnu)
  47        # Use libintl's gettext.sh, or fall back to English if we can't.
  48        . gettext.sh
  49        ;;
  50gettext_without_eval_gettext)
  51        # Solaris has a gettext(1) but no eval_gettext(1)
  52        eval_gettext () {
  53                gettext "$1" | (
  54                        export PATH $(git sh-i18n--envsubst --variables "$1");
  55                        git sh-i18n--envsubst "$1"
  56                )
  57        }
  58
  59        eval_ngettext () {
  60                ngettext "$1" "$2" "$3" | (
  61                        export PATH $(git sh-i18n--envsubst --variables "$2");
  62                        git sh-i18n--envsubst "$2"
  63                )
  64        }
  65        ;;
  66poison)
  67        # Emit garbage so that tests that incorrectly rely on translatable
  68        # strings will fail.
  69        gettext () {
  70                printf "%s" "# GETTEXT POISON #"
  71        }
  72
  73        eval_gettext () {
  74                printf "%s" "# GETTEXT POISON #"
  75        }
  76
  77        eval_ngettext () {
  78                printf "%s" "# GETTEXT POISON #"
  79        }
  80        ;;
  81*)
  82        gettext () {
  83                printf "%s" "$1"
  84        }
  85
  86        eval_gettext () {
  87                printf "%s" "$1" | (
  88                        export PATH $(git sh-i18n--envsubst --variables "$1");
  89                        git sh-i18n--envsubst "$1"
  90                )
  91        }
  92
  93        eval_ngettext () {
  94                (test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
  95                        export PATH $(git sh-i18n--envsubst --variables "$2");
  96                        git sh-i18n--envsubst "$2"
  97                )
  98        }
  99        ;;
 100esac
 101
 102# Git-specific wrapper functions
 103gettextln () {
 104        gettext "$1"
 105        echo
 106}
 107
 108eval_gettextln () {
 109        eval_gettext "$1"
 110        echo
 111}