All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð" <avarab@gmail.com>,
	"Jiang Xin" <worldhello.net@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/5] i18n: keep the last \n even when text is poisoned
Date: Thu,  8 Mar 2012 16:16:34 +0700	[thread overview]
Message-ID: <1331198198-22409-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1331198198-22409-1-git-send-email-pclouds@gmail.com>

This helps maintain the layout somewhat when translatable text is
poisoned.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 gettext.c |   10 ++++++++++
 gettext.h |    6 ++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gettext.c b/gettext.c
index f75bca7..60bc2ad 100644
--- a/gettext.c
+++ b/gettext.c
@@ -24,6 +24,16 @@ int use_gettext_poison(void)
 		poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
 	return poison_requested;
 }
+
+const char *poison_text(const char *msgid)
+{
+	int len = strlen(msgid);
+	if (len && msgid[len-1] == '\n')
+		return "# GETTEXT POISON #\n";
+	else
+		return "# GETTEXT POISON #";
+}
+
 #endif
 
 #ifndef NO_GETTEXT
diff --git a/gettext.h b/gettext.h
index 57ba8bb..2313c84 100644
--- a/gettext.h
+++ b/gettext.h
@@ -38,20 +38,22 @@ static inline void git_setup_gettext(void)
 
 #ifdef GETTEXT_POISON
 extern int use_gettext_poison(void);
+extern const char *poison_text(const char *msgid);
 #else
 #define use_gettext_poison() 0
+#define poison_text(x) NULL
 #endif
 
 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
 {
-	return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
+	return use_gettext_poison() ? poison_text(msgid) : gettext(msgid);
 }
 
 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
 const char *Q_(const char *msgid, const char *plu, unsigned long n)
 {
 	if (use_gettext_poison())
-		return "# GETTEXT POISON #";
+		return poison_text(msgid);
 	return ngettext(msgid, plu, n);
 }
 
-- 
1.7.3.1.256.g2539c.dirty

  reply	other threads:[~2012-03-08  9:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-08  9:16 [PATCH 0/5] i18n-ize relative dates, git-help and parseopt Nguyễn Thái Ngọc Duy
2012-03-08  9:16 ` Nguyễn Thái Ngọc Duy [this message]
2012-03-08 22:01   ` [PATCH 1/5] i18n: keep the last \n even when text is poisoned Jonathan Nieder
2012-03-09  1:11     ` Nguyen Thai Ngoc Duy
2012-03-09  2:33       ` Nguyen Thai Ngoc Duy
2012-03-09 11:24     ` Ævar Arnfjörð Bjarmason
2012-03-08  9:16 ` [PATCH 2/5] i18n: mark relative dates for translation Nguyễn Thái Ngọc Duy
2012-03-15 18:51   ` Jonathan Nieder
2012-03-15 19:16     ` Johannes Sixt
2012-03-15 19:18       ` Jonathan Nieder
2012-03-16 11:47     ` Nguyen Thai Ngoc Duy
2012-03-08  9:16 ` [PATCH 3/5] i18n: parseopt: lookup help and argument translations when showing usage Nguyễn Thái Ngọc Duy
2012-03-08 22:07   ` Jonathan Nieder
2012-03-08  9:16 ` [PATCH 4/5] i18n: help: mark parseopt strings for translation Nguyễn Thái Ngọc Duy
2012-03-08  9:16 ` [PATCH 5/5] i18n: help: mark " Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331198198-22409-2-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=worldhello.net@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.