i18n: git-sh-setup.sh: mark strings for translation

Positional arguments, such as $0, $1, etc, need to be stored on shell variables for use in translatable strings, according to gettext manual [1]. Add git-sh-setup.sh to LOCALIZED_SH variable in Makefile to enable extraction of string marked for translation by xgettext. Source git-sh-i18n in git-sh-setup.sh for gettext support. git-sh-setup.sh is a shell library to be sourced by other shell scripts. In order to avoid other scripts from sourcing git-sh-i18n twice, remove line that sources it from them. Not sourcing git-sh-i18n in any script that uses gettext would lead to failure due to, for instance, gettextln not being found. [1] http://www.gnu.org/software/gettext/manual/html_node/Preparing-Shell-Scripts.html Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vasco Almeida committed Jun 17, 2016 at 20:21 UTC d323c6b6410dee0a8a2471b4dbf6d631cd3c3d4d
7 files changed +50 -22
Makefile
+3 -1
@@ -2062,7 +2062,9 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
2062 --keyword=gettextln --keyword=eval_gettextln
2063 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
2064 LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
2065 -LOCALIZED_SH = $(SCRIPT_SH) git-parse-remote.sh
2065 +LOCALIZED_SH = $(SCRIPT_SH)
2066 +LOCALIZED_SH += git-parse-remote.sh
2067 +LOCALIZED_SH += git-sh-setup.sh
2068 LOCALIZED_PERL = $(SCRIPT_PERL)
2069
2070 ifdef XGETTEXT_INCLUDE_TESTS
git-bisect.sh
-1
@@ -33,7 +33,6 @@ Please use "git help bisect" to get the full man page.'
33
34 OPTIONS_SPEC=
35 . git-sh-setup
36 -. git-sh-i18n
36
37 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
38 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
git-merge-octopus.sh
-1
@@ -6,7 +6,6 @@
6 #
7
8 . git-sh-setup
9 -. git-sh-i18n
9
10 LF='
11 '
git-rebase.sh
-1
@@ -45,7 +45,6 @@ skip! skip current patch and continue
45 edit-todo! edit the todo list during an interactive rebase
46 "
47 . git-sh-setup
48 -. git-sh-i18n
48 set_reflog_action rebase
49 require_work_tree_exists
50 cd_to_toplevel
git-sh-setup.sh
+47 -16
@@ -2,6 +2,9 @@
2 # to set up some variables pointing at the normal git directories and
3 # a few helper shell functions.
4
5 +# Source git-sh-i18n for gettext support.
6 +. git-sh-i18n
7 +
8 # Having this variable in your environment would break scripts because
9 # you would cause "cd" to be taken to unexpected places. If you
10 # like CDPATH, define it for your interactive shell sessions without
@@ -83,16 +86,16 @@ if test -n "$OPTIONS_SPEC"; then
86 else
87 dashless=$(basename -- "$0" | sed -e 's/-/ /')
88 usage() {
86 - die "usage: $dashless $USAGE"
89 + die "$(eval_gettext "usage: \$dashless \$USAGE")"
90 }
91
92 if [ -z "$LONG_USAGE" ]
93 then
91 - LONG_USAGE="usage: $dashless $USAGE"
94 + LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE")"
95 else
93 - LONG_USAGE="usage: $dashless $USAGE
96 + LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE
97
95 -$LONG_USAGE"
98 +$LONG_USAGE")"
99 fi
100
101 case "$1" in
@@ -182,7 +185,7 @@ is_bare_repository () {
185 cd_to_toplevel () {
186 cdup=$(git rev-parse --show-toplevel) &&
187 cd "$cdup" || {
185 - echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
188 + gettextln "Cannot chdir to \$cdup, the toplevel of the working tree" >&2
189 exit 1
190 }
191 }
@@ -190,13 +193,16 @@ cd_to_toplevel () {
193 require_work_tree_exists () {
194 if test "z$(git rev-parse --is-bare-repository)" != zfalse
195 then
193 - die "fatal: $0 cannot be used without a working tree."
196 + program_name=$0
197 + die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
198 fi
199 }
200
201 require_work_tree () {
198 - test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
199 - die "fatal: $0 cannot be used without a working tree."
202 + test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true || {
203 + program_name=$0
204 + die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
205 + }
206 }
207
208 require_clean_work_tree () {
@@ -206,24 +212,49 @@ require_clean_work_tree () {
212
213 if ! git diff-files --quiet --ignore-submodules
214 then
209 - echo >&2 "Cannot $1: You have unstaged changes."
215 + action=$1
216 + case "$action" in
217 + rebase)
218 + gettextln "Cannot rebase: You have unstaged changes." >&2
219 + ;;
220 + "rewrite branches")
221 + gettextln "Cannot rewrite branches: You have unstaged changes." >&2
222 + ;;
223 + "pull with rebase")
224 + gettextln "Cannot pull with rebase: You have unstaged changes." >&2
225 + ;;
226 + *)
227 + eval_gettextln "Cannot \$action: You have unstaged changes." >&2
228 + ;;
229 + esac
230 err=1
231 fi
232
233 if ! git diff-index --cached --quiet --ignore-submodules HEAD --
234 then
215 - if [ $err = 0 ]
235 + if test $err = 0
236 then
217 - echo >&2 "Cannot $1: Your index contains uncommitted changes."
237 + action=$1
238 + case "$action" in
239 + rebase)
240 + gettextln "Cannot rebase: Your index contains uncommitted changes." >&2
241 + ;;
242 + "pull with rebase")
243 + gettextln "Cannot pull with rebase: Your index contains uncommitted changes." >&2
244 + ;;
245 + *)
246 + eval_gettextln "Cannot \$action: Your index contains uncommitted changes." >&2
247 + ;;
248 + esac
249 else
219 - echo >&2 "Additionally, your index contains uncommitted changes."
250 + gettextln "Additionally, your index contains uncommitted changes." >&2
251 fi
252 err=1
253 fi
254
224 - if [ $err = 1 ]
255 + if test $err = 1
256 then
226 - test -n "$2" && echo >&2 "$2"
257 + test -n "$2" && echo "$2" >&2
258 exit 1
259 fi
260 }
@@ -336,12 +367,12 @@ git_dir_init () {
367 then
368 test -z "$(git rev-parse --show-cdup)" || {
369 exit=$?
339 - echo >&2 "You need to run this command from the toplevel of the working tree."
370 + gettextln "You need to run this command from the toplevel of the working tree." >&2
371 exit $exit
372 }
373 fi
374 test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
344 - echo >&2 "Unable to determine absolute path of git directory"
375 + gettextln "Unable to determine absolute path of git directory" >&2
376 exit 1
377 }
378 : ${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}
git-stash.sh
-1
@@ -15,7 +15,6 @@ SUBDIRECTORY_OK=Yes
15 OPTIONS_SPEC=
16 START_DIR=$(pwd)
17 . git-sh-setup
18 -. git-sh-i18n
18 require_work_tree
19 cd_to_toplevel
20
git-submodule.sh
-1
@@ -16,7 +16,6 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
16 OPTIONS_SPEC=
17 SUBDIRECTORY_OK=Yes
18 . git-sh-setup
19 -. git-sh-i18n
19 . git-parse-remote
20 require_work_tree
21 wt_prefix=$(git rev-parse --show-prefix)