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

[PATCH 1/5] i18n: keep the last \n even when text is poisoned

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 8, 2012, 09:16 UTC
Message-ID
<1331198198-22409-2-git-send-email-pclouds@gmail.com>
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
Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 2 of 15 in “i18n-ize relative dates, git-help and parseopt”
  1. 0/5 i18n-ize relative dates, git-help and parseoptNguyễn Thái Ngọc Duy, Mar 8, 2012
  2. 1/5 i18n: keep the last \n even when text is poisonedNguyễn Thái Ngọc Duy, Mar 8, 2012
  3. Jonathan NiederMar 8, 2012
  4. Nguyen Thai Ngoc DuyMar 9, 2012
  5. Nguyen Thai Ngoc DuyMar 9, 2012
  6. Ævar Arnfjörð BjarmasonMar 9, 2012
  7. 2/5 i18n: mark relative dates for translationNguyễn Thái Ngọc Duy, Mar 8, 2012
  8. Jonathan NiederMar 15, 2012
  9. Johannes SixtMar 15, 2012
  10. Jonathan NiederMar 15, 2012
  11. Nguyen Thai Ngoc DuyMar 16, 2012
  12. 3/5 i18n: parseopt: lookup help and argument translations when showing usageNguyễn Thái Ngọc Duy, Mar 8, 2012
  13. Jonathan NiederMar 8, 2012
  14. 4/5 i18n: help: mark parseopt strings for translationNguyễn Thái Ngọc Duy, Mar 8, 2012
  15. 5/5 i18n: help: mark strings for translationNguyễn Thái Ngọc Duy, Mar 8, 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.