Skip to content

Commit d323c6b

Browse files
vascoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9e6ce4 commit d323c6b

File tree

7 files changed

+50
-22
lines changed

7 files changed

+50
-22
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,9 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
20622062
--keyword=gettextln --keyword=eval_gettextln
20632063
XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
20642064
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
20662068
LOCALIZED_PERL = $(SCRIPT_PERL)
20672069

20682070
ifdef XGETTEXT_INCLUDE_TESTS

git-bisect.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Please use "git help bisect" to get the full man page.'
3333

3434
OPTIONS_SPEC=
3535
. git-sh-setup
36-
. git-sh-i18n
3736

3837
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
3938
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"

git-merge-octopus.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#
77

88
. git-sh-setup
9-
. git-sh-i18n
109

1110
LF='
1211
'

git-rebase.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ skip! skip current patch and continue
4545
edit-todo! edit the todo list during an interactive rebase
4646
"
4747
. git-sh-setup
48-
. git-sh-i18n
4948
set_reflog_action rebase
5049
require_work_tree_exists
5150
cd_to_toplevel

git-sh-setup.sh

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# to set up some variables pointing at the normal git directories and
33
# a few helper shell functions.
44

5+
# Source git-sh-i18n for gettext support.
6+
. git-sh-i18n
7+
58
# Having this variable in your environment would break scripts because
69
# you would cause "cd" to be taken to unexpected places. If you
710
# like CDPATH, define it for your interactive shell sessions without
@@ -83,16 +86,16 @@ if test -n "$OPTIONS_SPEC"; then
8386
else
8487
dashless=$(basename -- "$0" | sed -e 's/-/ /')
8588
usage() {
86-
die "usage: $dashless $USAGE"
89+
die "$(eval_gettext "usage: \$dashless \$USAGE")"
8790
}
8891
8992
if [ -z "$LONG_USAGE" ]
9093
then
91-
LONG_USAGE="usage: $dashless $USAGE"
94+
LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE")"
9295
else
93-
LONG_USAGE="usage: $dashless $USAGE
96+
LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE
9497
95-
$LONG_USAGE"
98+
$LONG_USAGE")"
9699
fi
97100
98101
case "$1" in
@@ -182,21 +185,24 @@ is_bare_repository () {
182185
cd_to_toplevel () {
183186
cdup=$(git rev-parse --show-toplevel) &&
184187
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
186189
exit 1
187190
}
188191
}
189192
190193
require_work_tree_exists () {
191194
if test "z$(git rev-parse --is-bare-repository)" != zfalse
192195
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.")"
194198
fi
195199
}
196200
197201
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+
}
200206
}
201207
202208
require_clean_work_tree () {
@@ -206,24 +212,49 @@ require_clean_work_tree () {
206212
207213
if ! git diff-files --quiet --ignore-submodules
208214
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
210230
err=1
211231
fi
212232
213233
if ! git diff-index --cached --quiet --ignore-submodules HEAD --
214234
then
215-
if [ $err = 0 ]
235+
if test $err = 0
216236
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
218249
else
219-
echo >&2 "Additionally, your index contains uncommitted changes."
250+
gettextln "Additionally, your index contains uncommitted changes." >&2
220251
fi
221252
err=1
222253
fi
223254
224-
if [ $err = 1 ]
255+
if test $err = 1
225256
then
226-
test -n "$2" && echo >&2 "$2"
257+
test -n "$2" && echo "$2" >&2
227258
exit 1
228259
fi
229260
}
@@ -336,12 +367,12 @@ git_dir_init () {
336367
then
337368
test -z "$(git rev-parse --show-cdup)" || {
338369
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
340371
exit $exit
341372
}
342373
fi
343374
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
345376
exit 1
346377
}
347378
: ${GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)"}

git-stash.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ SUBDIRECTORY_OK=Yes
1515
OPTIONS_SPEC=
1616
START_DIR=$(pwd)
1717
. git-sh-setup
18-
. git-sh-i18n
1918
require_work_tree
2019
cd_to_toplevel
2120

git-submodule.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
1616
OPTIONS_SPEC=
1717
SUBDIRECTORY_OK=Yes
1818
. git-sh-setup
19-
. git-sh-i18n
2019
. git-parse-remote
2120
require_work_tree
2221
wt_prefix=$(git rev-parse --show-prefix)

0 commit comments

Comments
 (0)