* [RFC] gettext: add gettextln, eval_gettextln to encode common idiom
@ 2011-08-06 4:16 Jon Seymour
2011-08-06 4:58 ` Jon Seymour
2011-08-06 11:53 ` Ævar Arnfjörð Bjarmason
0 siblings, 2 replies; 3+ messages in thread
From: Jon Seymour @ 2011-08-06 4:16 UTC (permalink / raw)
To: git; +Cc: avarab, Jon Seymour
Currently, if you want to use gettext or eval_gettext to format a message
you may have to add a separate echo statement and a surrounding subshell
in order to interpolate the required trailing new line.
This patch introduces two new helper functions, gettextln and eval_gettextln
which append a trailing newline to the gettext output.
This allows constructions of the form:
if test -s "$GIT_DIR/BISECT_START"
then
(
gettext "You need to give me at least one good and one bad revisions.
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
echo
) >&2
else
...
to be expressed more concisely as:
if test -s "$GIT_DIR/BISECT_START"
then
gettextln "You need to give me at least one good and one bad revisions.
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
else
...
An example of its use in git-bisect.sh is given.
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
git-bisect.sh | 49 ++++++++++++++-----------------------------------
git-sh-i18n.sh | 19 +++++++++++++++++++
2 files changed, 33 insertions(+), 35 deletions(-)
This patch applies on top of Junio's "bisect: further style nitpicks" currently in kernel/pu.
FWIW, I am not attached to the suggested names. I can split the changes to git-sh-i18n.sh into a separate commit if there is agreement in principle to take the change.
diff --git a/git-bisect.sh b/git-bisect.sh
index 22c4da5..22c0e28 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -46,10 +46,7 @@ bisect_head()
bisect_autostart() {
test -s "$GIT_DIR/BISECT_START" || {
- (
- gettext "You need to start by \"git bisect start\"" &&
- echo
- ) >&2
+ gettextln "You need to start by \"git bisect start\"" >&2
if test -t 0
then
# TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -268,10 +265,7 @@ bisect_next_check() {
t,,good)
# have bad but not good. we could bisect although
# this is less optimum.
- (
- gettext "Warning: bisecting only with a bad commit." &&
- echo
- ) >&2
+ gettextln "Warning: bisecting only with a bad commit." >&2
if test -t 0
then
# TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -287,18 +281,12 @@ bisect_next_check() {
if test -s "$GIT_DIR/BISECT_START"
then
- (
- gettext "You need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
- echo
- ) >&2
+ gettextln "You need to give me at least one good and one bad revisions.
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
else
- (
- gettext "You need to start by \"git bisect start\".
+ gettextln "You need to start by \"git bisect start\".
You then need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
- echo
- ) >&2
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
fi
exit 1 ;;
esac
@@ -351,7 +339,7 @@ bisect_visualize() {
bisect_reset() {
test -s "$GIT_DIR/BISECT_START" || {
- gettext "We are not bisecting."; echo
+ gettextln "We are not bisecting."
return
}
case "$#" in
@@ -424,18 +412,15 @@ bisect_run () {
while true
do
command="$@"
- eval_gettext "running \$command"; echo
+ eval_gettextln "running \$command"
"$@"
res=$?
# Check for really bad run error.
if [ $res -lt 0 -o $res -ge 128 ]
then
- (
- eval_gettext "bisect run failed:
-exit code \$res from '\$command' is < 0 or >= 128" &&
- echo
- ) >&2
+ eval_gettextln "bisect run failed:
+exit code \$res from '\$command' is < 0 or >= 128" >&2
exit $res
fi
@@ -460,26 +445,20 @@ exit code \$res from '\$command' is < 0 or >= 128" &&
if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
> /dev/null
then
- (
- gettext "bisect run cannot continue any more" &&
- echo
- ) >&2
+ gettextln "bisect run cannot continue any more" >&2
exit $res
fi
if [ $res -ne 0 ]
then
- (
- eval_gettext "bisect run failed:
-'bisect_state \$state' exited with error code \$res" &&
- echo
- ) >&2
+ eval_gettextln "bisect run failed:
+'bisect_state \$state' exited with error code \$res" >&2
exit $res
fi
if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null
then
- gettext "bisect run success"; echo
+ gettextln "bisect run success"
exit 0;
fi
diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index 32ca59d..e672366 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -11,19 +11,38 @@ then
printf "%s" "$1"
}
+ gettextln() {
+ printf "%s\n" "$1"
+ }
+
eval_gettext () {
printf "%s" "$1" | (
export PATH $(git sh-i18n--envsubst --variables "$1");
git sh-i18n--envsubst "$1"
)
}
+
+ eval_gettextln () {
+ printf "%s\n" "$1" | (
+ export PATH $(git sh-i18n--envsubst --variables "$1");
+ git sh-i18n--envsubst "$1"
+ )
+ }
else
gettext () {
printf "%s" "# GETTEXT POISON #"
}
+ gettextln () {
+ printf "%s\n" "# GETTEXT POISON #"
+ }
+
eval_gettext () {
printf "%s" "# GETTEXT POISON #"
}
+
+ eval_gettextln () {
+ printf "%s\n" "# GETTEXT POISON #"
+ }
fi
--
1.7.6.362.gf0e6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC] gettext: add gettextln, eval_gettextln to encode common idiom
2011-08-06 4:16 [RFC] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
@ 2011-08-06 4:58 ` Jon Seymour
2011-08-06 11:53 ` Ævar Arnfjörð Bjarmason
1 sibling, 0 replies; 3+ messages in thread
From: Jon Seymour @ 2011-08-06 4:58 UTC (permalink / raw)
To: git; +Cc: avarab, Jon Seymour
On Sat, Aug 6, 2011 at 2:16 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
>
> An example of its use in git-bisect.sh is given.
>
Other scripts which could benefit from such a function are:
git-am.sh
git-pull.sh
git-quiltimport.sh
git-stash.sh
git-submodule.sh
jon.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] gettext: add gettextln, eval_gettextln to encode common idiom
2011-08-06 4:16 [RFC] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
2011-08-06 4:58 ` Jon Seymour
@ 2011-08-06 11:53 ` Ævar Arnfjörð Bjarmason
1 sibling, 0 replies; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2011-08-06 11:53 UTC (permalink / raw)
To: Jon Seymour; +Cc: git
On Sat, Aug 6, 2011 at 06:16, Jon Seymour <jon.seymour@gmail.com> wrote:
> This patch introduces two new helper functions, gettextln and eval_gettextln
> which append a trailing newline to the gettext output.
I like this, I would have done this myself but didn't have time.
Acked-by me
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-06 11:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-06 4:16 [RFC] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
2011-08-06 4:58 ` Jon Seymour
2011-08-06 11:53 ` Ævar Arnfjörð Bjarmason
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.