git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] i18n: Add extra -- to seperate gettext and message

From
Jiang Xin <worldhello.net@gmail.com>
Date
Jun 3, 2012, 23:09 UTC
Message-ID
<1338764967-30103-2-git-send-email-worldhello.net@gmail.com>
In-Reply-To
<1338764967-30103-1-git-send-email-worldhello.net@gmail.com>

In commit b9b9c22, Ævar addressed a issue when gettextized a message started with "--", such as "--cached cannot be used with --files", the first word in the message would be treated as an option of gettext, and might raise a bad option error.

The solution Ævar provided is to add a extra "--" option between gettext and the message. But Vincent fount out later that the extra "--" was extracted as gettext message by xgettext instead of the real message. See:

 * http://thread.gmane.org/gmane.comp.version-control.git/199042

In order to fix this dilemma, we move the extra "--" option from gettext to gettext wrapper (gettextln, and eval_gettext), and gettextize the message using the wrapper function instead of gettext itself.

But for system with libintl's gettext.sh, eval_gettext and eval_gettextln won't have this fix.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
---
 git-sh-i18n.sh   | 8 ++++++--
 git-submodule.sh | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index 6a27f..1c61e4 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -49,7 +49,7 @@ gnu)
 gettext_without_eval_gettext)
 	# Solaris has a gettext(1) but no eval_gettext(1)
 	eval_gettext () {
-		gettext "$1" | (
+		gettext -- "$1" | (
 			export PATH $(git sh-i18n--envsubst --variables "$1");
 			git sh-i18n--envsubst "$1"
 		)
@@ -68,10 +68,14 @@ poison)
 	;;
 *)
 	gettext () {
+		# Bypass options, such as '--'.
+		shift $(($# - 1))
 		printf "%s" "$1"
 	}
 
 	eval_gettext () {
+		# Bypass options, such as '--'.
+		shift $(($# - 1))
 		printf "%s" "$1" | (
 			export PATH $(git sh-i18n--envsubst --variables "$1");
 			git sh-i18n--envsubst "$1"
@@ -82,7 +86,7 @@ esac
 
 # Git-specific wrapper functions
 gettextln () {
-	gettext "$1"
+	gettext -- "$1"
 	echo
 }
 
diff --git a/git-submodule.sh b/git-submodule.sh
index 5c61a..bb9f6 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -710,7 +710,7 @@ cmd_summary() {
 	if [ -n "$files" ]
 	then
 		test -n "$cached" &&
-		die "$(gettext -- "--cached cannot be used with --files")"
+		die "$(gettextln "--cached cannot be used with --files")"
 		diff_cmd=diff-files
 		head=
 	fi
-- 
1.7.10.2.559.g0ba0f00
Previous: Jiang XinNext: Ævar Arnfjörð Bjarmason
Message 2 of 8 in “i18n: Extract msgs marked by sh gettext wrappers”
  1. 1/2 i18n: Extract msgs marked by sh gettext wrappersJiang Xin, Jun 3, 2012
  2. 2/2 i18n: Add extra -- to seperate gettext and messageJiang Xin, Jun 3, 2012
  3. Ævar Arnfjörð BjarmasonJun 4, 2012
  4. Jiang XinJun 4, 2012
  5. Junio C HamanoJun 4, 2012
  6. Jiang XinJun 15, 2012
  7. Jonathan NiederJun 15, 2012
  8. Junio C HamanoJun 15, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.