i18n: mark relative dates for translation
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9a0a30aa4b
commit
7d29afd43c
6
cache.h
6
cache.h
@ -920,10 +920,8 @@ enum date_mode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char *show_date(unsigned long time, int timezone, enum date_mode mode);
|
const char *show_date(unsigned long time, int timezone, enum date_mode mode);
|
||||||
const char *show_date_relative(unsigned long time, int tz,
|
void show_date_relative(unsigned long time, int tz, const struct timeval *now,
|
||||||
const struct timeval *now,
|
struct strbuf *timebuf);
|
||||||
char *timebuf,
|
|
||||||
size_t timebuf_size);
|
|
||||||
int parse_date(const char *date, char *buf, int bufsize);
|
int parse_date(const char *date, char *buf, int bufsize);
|
||||||
int parse_date_basic(const char *date, unsigned long *timestamp, int *offset);
|
int parse_date_basic(const char *date, unsigned long *timestamp, int *offset);
|
||||||
void datestamp(char *buf, int bufsize);
|
void datestamp(char *buf, int bufsize);
|
||||||
|
95
date.c
95
date.c
@ -86,83 +86,98 @@ static int local_tzoffset(unsigned long time)
|
|||||||
return offset * eastwest;
|
return offset * eastwest;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *show_date_relative(unsigned long time, int tz,
|
void show_date_relative(unsigned long time, int tz,
|
||||||
const struct timeval *now,
|
const struct timeval *now,
|
||||||
char *timebuf,
|
struct strbuf *timebuf)
|
||||||
size_t timebuf_size)
|
|
||||||
{
|
{
|
||||||
unsigned long diff;
|
unsigned long diff;
|
||||||
if (now->tv_sec < time)
|
if (now->tv_sec < time) {
|
||||||
return "in the future";
|
strbuf_addstr(timebuf, _("in the future"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
diff = now->tv_sec - time;
|
diff = now->tv_sec - time;
|
||||||
if (diff < 90) {
|
if (diff < 90) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu seconds ago", diff);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu second ago", "%lu seconds ago", diff), diff);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Turn it into minutes */
|
/* Turn it into minutes */
|
||||||
diff = (diff + 30) / 60;
|
diff = (diff + 30) / 60;
|
||||||
if (diff < 90) {
|
if (diff < 90) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu minutes ago", diff);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu minute ago", "%lu minutes ago", diff), diff);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Turn it into hours */
|
/* Turn it into hours */
|
||||||
diff = (diff + 30) / 60;
|
diff = (diff + 30) / 60;
|
||||||
if (diff < 36) {
|
if (diff < 36) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu hours ago", diff);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu hour ago", "%lu hours ago", diff), diff);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* We deal with number of days from here on */
|
/* We deal with number of days from here on */
|
||||||
diff = (diff + 12) / 24;
|
diff = (diff + 12) / 24;
|
||||||
if (diff < 14) {
|
if (diff < 14) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu days ago", diff);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu day ago", "%lu days ago", diff), diff);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Say weeks for the past 10 weeks or so */
|
/* Say weeks for the past 10 weeks or so */
|
||||||
if (diff < 70) {
|
if (diff < 70) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu weeks ago", (diff + 3) / 7);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu week ago", "%lu weeks ago", (diff + 3) / 7),
|
||||||
|
(diff + 3) / 7);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Say months for the past 12 months or so */
|
/* Say months for the past 12 months or so */
|
||||||
if (diff < 365) {
|
if (diff < 365) {
|
||||||
snprintf(timebuf, timebuf_size, "%lu months ago", (diff + 15) / 30);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu month ago", "%lu months ago", (diff + 15) / 30),
|
||||||
|
(diff + 15) / 30);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Give years and months for 5 years or so */
|
/* Give years and months for 5 years or so */
|
||||||
if (diff < 1825) {
|
if (diff < 1825) {
|
||||||
unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
|
unsigned long totalmonths = (diff * 12 * 2 + 365) / (365 * 2);
|
||||||
unsigned long years = totalmonths / 12;
|
unsigned long years = totalmonths / 12;
|
||||||
unsigned long months = totalmonths % 12;
|
unsigned long months = totalmonths % 12;
|
||||||
int n;
|
if (months) {
|
||||||
n = snprintf(timebuf, timebuf_size, "%lu year%s",
|
struct strbuf sb = STRBUF_INIT;
|
||||||
years, (years > 1 ? "s" : ""));
|
strbuf_addf(&sb, Q_("%lu year", "%lu years", years), years);
|
||||||
if (months)
|
/* TRANSLATORS: "%s" is "<n> years" */
|
||||||
snprintf(timebuf + n, timebuf_size - n,
|
strbuf_addf(timebuf,
|
||||||
", %lu month%s ago",
|
Q_("%s, %lu month ago", "%s, %lu months ago", months),
|
||||||
months, (months > 1 ? "s" : ""));
|
sb.buf, months);
|
||||||
else
|
strbuf_release(&sb);
|
||||||
snprintf(timebuf + n, timebuf_size - n, " ago");
|
} else
|
||||||
return timebuf;
|
strbuf_addf(timebuf,
|
||||||
|
Q_("%lu year ago", "%lu years ago", years), years);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/* Otherwise, just years. Centuries is probably overkill. */
|
/* Otherwise, just years. Centuries is probably overkill. */
|
||||||
snprintf(timebuf, timebuf_size, "%lu years ago", (diff + 183) / 365);
|
strbuf_addf(timebuf,
|
||||||
return timebuf;
|
Q_("%lu year ago", "%lu years ago", (diff + 183) / 365),
|
||||||
|
(diff + 183) / 365);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *show_date(unsigned long time, int tz, enum date_mode mode)
|
const char *show_date(unsigned long time, int tz, enum date_mode mode)
|
||||||
{
|
{
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
static char timebuf[200];
|
static struct strbuf timebuf = STRBUF_INIT;
|
||||||
|
|
||||||
if (mode == DATE_RAW) {
|
if (mode == DATE_RAW) {
|
||||||
snprintf(timebuf, sizeof(timebuf), "%lu %+05d", time, tz);
|
strbuf_reset(&timebuf);
|
||||||
return timebuf;
|
strbuf_addf(&timebuf, "%lu %+05d", time, tz);
|
||||||
|
return timebuf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == DATE_RELATIVE) {
|
if (mode == DATE_RELATIVE) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
|
strbuf_reset(&timebuf);
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
return show_date_relative(time, tz, &now,
|
show_date_relative(time, tz, &now, &timebuf);
|
||||||
timebuf, sizeof(timebuf));
|
return timebuf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == DATE_LOCAL)
|
if (mode == DATE_LOCAL)
|
||||||
@ -171,23 +186,25 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
|
|||||||
tm = time_to_tm(time, tz);
|
tm = time_to_tm(time, tz);
|
||||||
if (!tm)
|
if (!tm)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
strbuf_reset(&timebuf);
|
||||||
if (mode == DATE_SHORT)
|
if (mode == DATE_SHORT)
|
||||||
sprintf(timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
|
strbuf_addf(&timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
|
||||||
tm->tm_mon + 1, tm->tm_mday);
|
tm->tm_mon + 1, tm->tm_mday);
|
||||||
else if (mode == DATE_ISO8601)
|
else if (mode == DATE_ISO8601)
|
||||||
sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
|
strbuf_addf(&timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
|
||||||
tm->tm_year + 1900,
|
tm->tm_year + 1900,
|
||||||
tm->tm_mon + 1,
|
tm->tm_mon + 1,
|
||||||
tm->tm_mday,
|
tm->tm_mday,
|
||||||
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
||||||
tz);
|
tz);
|
||||||
else if (mode == DATE_RFC2822)
|
else if (mode == DATE_RFC2822)
|
||||||
sprintf(timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
|
strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
|
||||||
weekday_names[tm->tm_wday], tm->tm_mday,
|
weekday_names[tm->tm_wday], tm->tm_mday,
|
||||||
month_names[tm->tm_mon], tm->tm_year + 1900,
|
month_names[tm->tm_mon], tm->tm_year + 1900,
|
||||||
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
|
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
|
||||||
else
|
else
|
||||||
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
|
strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
|
||||||
weekday_names[tm->tm_wday],
|
weekday_names[tm->tm_wday],
|
||||||
month_names[tm->tm_mon],
|
month_names[tm->tm_mon],
|
||||||
tm->tm_mday,
|
tm->tm_mday,
|
||||||
@ -195,7 +212,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
|
|||||||
tm->tm_year + 1900,
|
tm->tm_year + 1900,
|
||||||
(mode == DATE_LOCAL) ? 0 : ' ',
|
(mode == DATE_LOCAL) ? 0 : ' ',
|
||||||
tz);
|
tz);
|
||||||
return timebuf;
|
return timebuf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -7,13 +7,14 @@ static const char *usage_msg = "\n"
|
|||||||
|
|
||||||
static void show_dates(char **argv, struct timeval *now)
|
static void show_dates(char **argv, struct timeval *now)
|
||||||
{
|
{
|
||||||
char buf[128];
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
for (; *argv; argv++) {
|
for (; *argv; argv++) {
|
||||||
time_t t = atoi(*argv);
|
time_t t = atoi(*argv);
|
||||||
show_date_relative(t, 0, now, buf, sizeof(buf));
|
show_date_relative(t, 0, now, &buf);
|
||||||
printf("%s -> %s\n", *argv, buf);
|
printf("%s -> %s\n", *argv, buf.buf);
|
||||||
}
|
}
|
||||||
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_dates(char **argv, struct timeval *now)
|
static void parse_dates(char **argv, struct timeval *now)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user