Merge branch 'ab/i18n' into ab/test-1
[git/dscho.git] / git-sh-i18n.sh
blob698a000fe5347c73cecd2de5d786dcaf1ef22cc5
1 #!/bin/sh
3 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
5 # This is Git's interface to gettext.sh. Use it right after
6 # git-sh-setup as:
8 # . git-sh-setup
9 # . git-sh-i18n
11 # # For constant interface messages:
12 # gettext "A message for the user"; echo
14 # # To interpolate variables:
15 # details="oh noes"
16 # eval_gettext "An error occured: \$details"; echo
18 # See "info '(gettext)sh'" for the full manual.
20 # Export the TEXTDOMAIN* data that we need for Git
21 TEXTDOMAIN=git
22 export TEXTDOMAIN
23 if [ -z "$GIT_TEXTDOMAINDIR" ]
24 then
25 TEXTDOMAINDIR="@@LOCALEDIR@@"
26 else
27 TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
29 export TEXTDOMAINDIR
31 if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
32 then
33 # This is GNU libintl's gettext.sh, we don't need to do anything
34 # else than setting up the environment and loading gettext.sh
35 GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
36 export GIT_INTERNAL_GETTEXT_SH_SCHEME
38 # Try to use libintl's gettext.sh, or fall back to English if we
39 # can't.
40 . gettext.sh
41 elif test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && test "$(gettext -h 2>&1)" = "-h"
42 then
43 # We don't have gettext.sh, but there's a gettext binary in our
44 # path. This is probably Solaris or something like it which has a
45 # gettext implementation that isn't GNU libintl.
46 GIT_INTERNAL_GETTEXT_SH_SCHEME=solaris
47 export GIT_INTERNAL_GETTEXT_SH_SCHEME
49 # Solaris has a gettext(1) but no eval_gettext(1)
50 eval_gettext () {
51 gettext_out=$(gettext "$1")
52 gettext_eval="printf '%s' \"$gettext_out\""
53 printf "%s" "`eval \"$gettext_eval\"`"
55 else
56 # Since gettext.sh isn't available we'll have to define our own
57 # dummy pass-through functions.
59 # Tell our tests that we don't have the real gettext.sh
60 GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
61 export GIT_INTERNAL_GETTEXT_SH_SCHEME
63 gettext () {
64 printf "%s" "$1"
67 eval_gettext () {
68 gettext_eval="printf '%s' \"$1\""
69 printf "%s" "`eval \"$gettext_eval\"`"