From: Junio C Hamano <gitster@pobox.com>
To: Jiang Xin <worldhello.net@gmail.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
Eric Sunshine <sunshine@sunshineco.com>,
Brian Gesiak <modocache@gmail.com>,
Git List <git@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] blame: use a helper to get suitable blame_date_width
Date: Mon, 21 Apr 2014 10:20:44 -0700 [thread overview]
Message-ID: <xmqqfvl6a9ar.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <17454bdfbd4e0e1516a64f75deabddb427792e99.1398059411.git.worldhello.net@gmail.com> (Jiang Xin's message of "Mon, 21 Apr 2014 14:02:04 +0800")
Jiang Xin <worldhello.net@gmail.com> writes:
> When show date in relative date format for git-blame, the max display
> width of datetime is set as the length of the string "Thu Oct 19
> 16:00:04 2006 -0700" (30 characters long). But actually the max width
> for C locale is only 22 (the length of string "x years, xx months ago").
> And for other locale, it maybe smaller. E.g. For Chinese locale, only
> needs a half (16-character width).
>
> Add a helper function date_relative_maxwidth() to date.c, which returns
> the suitable display width for the relative date field in different
> locale.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
> ---
> builtin/blame.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 63 insertions(+), 1 deletion(-)
That does not seem to have the helper in date.c immediately next to
the definition of show_date_relative(), as the above log message
claims, does it?
I was hoping that you would respond with a set of counter-arugments
to shoot the suggestion down. Here are a few obvious ones:
- By inlining the implementation of show_date_relative() in the new
helper function, we would end up having to maintain two copies of
every format strings.
- Even if we don't inline the logic and duplicate the format
strings, and call show_date_relative() with some predetermined
offsets instead, e.g.
static int date_relative_maxwidth(void)
{
struct timebuf = STRBUF_INIT;
struct timeval now;
static int maxwidth = 0;
gettimeofday(&now, NULL);
/* in the future */
show_date_relative(now->tv_sec + 100, 0, &now, &timebuf);
maxwidth = maxwidth < timebuf.len ? timebuf.len : maxwidth;
strbuf_reset(&timebuf);
/* seconds ago */
show_date_relative(now->tv_sec - 89, 0, &now, &timebuf);
maxwidth = maxwidth < timebuf.len ? timebuf.len : maxwidth;
strbuf_reset(&timebuf);
...
}
we still end up hardcoding the logic in the code.
- There is no guarantee that these predetermined offsets would
produce the longest possible timestamp for the target language
with these gettext strings. In a language where the noun
"second" takes a lot longer shape for singular than the plural
(e.g. "1 SECOND" vs "2 SEC", perhaps), checking for 89 seconds
ago may not produce the longest string for "%lu seconds ago".
The approach, "we compute everything for translators", sounds
nice in theory, but may not work well in practice and the worst
part is that there is no way for translators to work it around,
unlike your original patch.
So after sleeping on the idea overnight, I think I like the
simplicity of your original patch better. It just needs to be
explained well for translators to understand.
Sorry for making you go off exploring in a strange direction.
When msgmerge is run to update XX.po with a new version of git.pot,
does it destroy comments an earlier translator placed in XX.po, or
are they kept intact? What I am wondering is if we can do something
like this:
In code:
blame_date_width = strtoul(_("22 (C)"), NULL, 10) + 1; /* add the null */
In git.pot:
#. This string encodes the preferred maximum display width for a
#. relative timestamp in "git blame" output. For C locale, "4 years,
#. 11 months ago", which takes 22 places, is the longest among various
#. forms of relative timestamps, but your languate may need more or
#. fewer display columns. If "zh_CN" locale needs 14 display columns to
#. hold any relative timestamp in the reasonably near past, for
#. example, translate this string as "14 (zh_CN)".
msgid "22 (C)"
msgstr ""
In de.po:
#. This string encodes the preferred maximum display width for a
#. relative timestamp in "git blame" output. For C locale, "4 years,
#. 11 months ago", which takes 22 places, is the longest among various
#. forms of relative timestamps, but your languate may need more or
#. fewer display columns. If zh_CN locale needs 14 display columns to
#. hold any relative timestamp in the reasonably near past, for
#. example, translate this string as "14 (zh_CN)".
#.
#. In de locale, "vor %lu Jahren, und %lu Monaten" is the
#. longest and fits within 28 display columns.
msgid "22 (C)"
msgstr "28 (de)"
where the instructions for tranlators to various languages come from
git.pot and the translator to a specific language can describe which
variant in the language described in XX.po is the longest. For that
to work well, the last two lines in the comment an earlier "de"
translator added need to be preserved across msgmerge, though.
next prev parent reply other threads:[~2014-04-21 17:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-18 8:44 [PATCH] blame: add correct paddings in time_buf for align Jiang Xin
2014-04-18 14:42 ` Duy Nguyen
2014-04-18 17:08 ` Junio C Hamano
2014-04-19 0:20 ` Duy Nguyen
2014-04-20 16:13 ` [PATCH v2 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-20 16:13 ` [PATCH v2 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-20 20:28 ` Eric Sunshine
2014-04-20 16:13 ` [PATCH v2 2/2] blame: use different blame_date_width for different locale Jiang Xin
2014-04-20 21:40 ` Junio C Hamano
2014-04-21 6:02 ` [PATCH v3 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-21 6:02 ` [PATCH v3 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-21 6:02 ` [PATCH v3 2/2] blame: use a helper to get suitable blame_date_width Jiang Xin
2014-04-21 17:20 ` Junio C Hamano [this message]
2014-04-21 19:19 ` Junio C Hamano
2014-04-22 12:25 ` Jiang Xin
2014-04-22 14:39 ` [PATCH v4 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-22 14:39 ` [PATCH v4 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-22 14:39 ` [PATCH v4 2/2] blame: dynamic blame_date_width for different locales Jiang Xin
2014-04-22 10:01 ` [PATCH v2 2/2] blame: use different blame_date_width for different locale David Kastrup
2014-04-22 12:16 ` Jiang Xin
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=xmqqfvl6a9ar.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=modocache@gmail.com \
--cc=pclouds@gmail.com \
--cc=sunshine@sunshineco.com \
--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.