git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / 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 2/5] i18n: mark relative dates for translation
Date: Thu,  8 Mar 2012 16:16:35 +0700	[thread overview]
Message-ID: <1331198198-22409-3-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1331198198-22409-1-git-send-email-pclouds@gmail.com>

English dates get correct plural/singular form as a side effect.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 date.c |   46 +++++++++++++++++++++++++++++-----------------
 1 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/date.c b/date.c
index a5055ca..063f344 100644
--- a/date.c
+++ b/date.c
@@ -93,38 +93,46 @@ const char *show_date_relative(unsigned long time, int tz,
 {
 	unsigned long diff;
 	if (now->tv_sec < time)
-		return "in the future";
+		return _("in the future");
 	diff = now->tv_sec - time;
 	if (diff < 90) {
-		snprintf(timebuf, timebuf_size, "%lu seconds ago", diff);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu second ago", "%lu seconds ago", diff), diff);
 		return timebuf;
 	}
 	/* Turn it into minutes */
 	diff = (diff + 30) / 60;
 	if (diff < 90) {
-		snprintf(timebuf, timebuf_size, "%lu minutes ago", diff);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu minute ago", "%lu minutes ago", diff), diff);
 		return timebuf;
 	}
 	/* Turn it into hours */
 	diff = (diff + 30) / 60;
 	if (diff < 36) {
-		snprintf(timebuf, timebuf_size, "%lu hours ago", diff);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu hour ago", "%lu hours ago", diff), diff);
 		return timebuf;
 	}
 	/* We deal with number of days from here on */
 	diff = (diff + 12) / 24;
 	if (diff < 14) {
-		snprintf(timebuf, timebuf_size, "%lu days ago", diff);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu day ago", "%lu days ago", diff), diff);
 		return timebuf;
 	}
 	/* Say weeks for the past 10 weeks or so */
 	if (diff < 70) {
-		snprintf(timebuf, timebuf_size, "%lu weeks ago", (diff + 3) / 7);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu week ago", "%lu weeks ago", (diff + 3) / 7),
+			 (diff + 3) / 7);
 		return timebuf;
 	}
 	/* Say months for the past 12 months or so */
 	if (diff < 365) {
-		snprintf(timebuf, timebuf_size, "%lu months ago", (diff + 15) / 30);
+		snprintf(timebuf, timebuf_size,
+			 Q_("%lu month ago", "%lu months ago", (diff + 15) / 30),
+			 (diff + 15) / 30);
 		return timebuf;
 	}
 	/* Give years and months for 5 years or so */
@@ -132,19 +140,23 @@ const char *show_date_relative(unsigned long time, int tz,
 		unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
 		unsigned long years = totalmonths / 12;
 		unsigned long months = totalmonths % 12;
-		int n;
-		n = snprintf(timebuf, timebuf_size, "%lu year%s",
-				years, (years > 1 ? "s" : ""));
-		if (months)
-			snprintf(timebuf + n, timebuf_size - n,
-					", %lu month%s ago",
-					months, (months > 1 ? "s" : ""));
-		else
-			snprintf(timebuf + n, timebuf_size - n, " ago");
+		if (months) {
+			struct strbuf sb = STRBUF_INIT;
+			strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
+			/* TRANSLATORS: "%s" is "<n> years" */
+			snprintf(timebuf, timebuf_size,
+				 Q_("%s, %lu month ago", "%s, %lu months ago", months),
+				 sb.buf, months);
+			strbuf_release(&sb);
+		} else
+			snprintf(timebuf, timebuf_size,
+				 Q_("%lu year ago", "%lu years ago", years), years);
 		return timebuf;
 	}
 	/* Otherwise, just years. Centuries is probably overkill. */
-	snprintf(timebuf, timebuf_size, "%lu years ago", (diff + 183) / 365);
+	snprintf(timebuf, timebuf_size,
+		 Q_("%lu year ago", "%lu years ago", (diff + 183) / 365),
+		 (diff + 183) / 365);
 	return timebuf;
 }
 
-- 
1.7.3.1.256.g2539c.dirty

  parent 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 ` [PATCH 1/5] i18n: keep the last \n even when text is poisoned Nguyễn Thái Ngọc Duy
2012-03-08 22:01   ` 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 ` Nguyễn Thái Ngọc Duy [this message]
2012-03-15 18:51   ` [PATCH 2/5] i18n: mark relative dates for translation 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1331198198-22409-3-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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).