git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Xin <worldhello.net@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Git List" <git@vger.kernel.org>,
	"Ævar Arnfjörð" <avarab@gmail.com>,
	"Jens Lehmann" <Jens.Lehmann@web.de>
Subject: Re: [PATCH] i18n: Not add stripped contents for translation
Date: Tue, 6 Mar 2012 12:16:06 +0800	[thread overview]
Message-ID: <CANYiYbHGAG5ijeL3yW5SKYAfMNwtme5ELPeGNPhNyKBPGTONMg@mail.gmail.com> (raw)
In-Reply-To: <7vobsb67dn.fsf@alter.siamese.dyndns.org>

2012/3/5 Junio C Hamano <gitster@pobox.com>:
> This is a tangent and I am just showing aloud my ignorance, but I wonder
> if there is a reasonably generic and "best current practice" way to
> structure code to show an enumeration in human languages, for example,
>
>        A, B, C and D.
>
> in an easier-to-translate way.
>
> I suspect that it might be sufficiently generic if we can make it possible
> to allow the first and the last inter-word-separation and the token after
> all the items to be different from other inter-word-separation tokens.
>
> E.g. in English, the first one and all the "other" are ", ", the last
> inter-word token is " and ", and the token at the very end is ".". In
> Japanese some translators may want to say "AやBとCとD。", meaning the
> first one is "や", "。" is used at the very end, and all the others may be
> "と".

I write a function for this.

/*
 * Make list of items easy for l10n translation.
 *
 *   1. Input list of items one by one through the 2nd argument,
 *      but leave the 1st argument as NULL.
 *
 *   2. Get the output joint string from the 1st argument.
 *
 * According to the number of items input. The joint string maybe:
 *
 *   a
 *   a and b
 *   a, b and c
 *   a, b, c and d
 *
 */
#define MAX_L10N_LIST_ITEMS_COUNT  128
void append_l10n_list_items(struct strbuf *ret, const char *item)
{
    static const char **itemlist = NULL;
    static int  count = 0;
    int i = 0;

    if (itemlist == NULL)
        itemlist = xmalloc(MAX_L10N_LIST_ITEMS_COUNT * sizeof(char*));

    if(item != NULL && count < MAX_L10N_LIST_ITEMS_COUNT )
        itemlist[count++] = item;

    if (ret != NULL) {
        if (count == 1) {
            strbuf_addstr(ret, itemlist[0]);
        }
        else if (count == 2) {
            strbuf_addf(ret, _("%s and %s"), itemlist[0], itemlist[1]);
        }
        else if (count > 2) {
            strbuf_addf(ret, _("%s, "), itemlist[0]);
            for (i=1; i<count-2; i++) {
                strbuf_addstr(ret, itemlist[i]);
                strbuf_addstr(ret, _(", "));
            }
            strbuf_addf(ret, _("%s and %s"), itemlist[count-2],
itemlist[count-1]);
        }
        free(itemlist);
        itemlist = NULL;
        count = 0;
    }
}


...
       strbuf_addstr(&extra, " ("))
       if (a)
               append_l10n_list_items(NULL, _("msg a"));
       if (b)
               append_l10n_list_items(NULL, _("msg b"));
       if (c)
               append_l10n_list_items(NULL, _("msg c"));

       append_l10n_list_items(&extra, NULL);
...

-- 
Jiang Xin

  parent reply	other threads:[~2012-03-06  4:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-05  1:21 [PATCH] i18n: Not add stripped contents for translation Jiang Xin
2012-03-05  2:27 ` Junio C Hamano
2012-03-05  3:01   ` Jiang Xin
2012-03-05  3:42     ` Junio C Hamano
2012-03-05 19:34       ` Jens Lehmann
2012-03-05 20:08         ` Junio C Hamano
2012-03-06  4:16       ` Jiang Xin [this message]
2012-03-06  6:46         ` Junio C Hamano
2012-03-06  6:55           ` Jiang Xin
2012-03-06  6:47         ` 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=CANYiYbHGAG5ijeL3yW5SKYAfMNwtme5ELPeGNPhNyKBPGTONMg@mail.gmail.com \
    --to=worldhello.net@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 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 NNTP newsgroup(s).