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

Re: [PATCH] i18n: Not add stripped contents for translation

From
Jiang Xin <worldhello.net@gmail.com>
Date
Mar 6, 2012, 06:47 UTC
Message-ID
<CANYiYbFXP_rB82-_ObnPE7NkKpv8NsA7=yu1VY7nRwkRPY5X_A@mail.gmail.com>
In-Reply-To
<CANYiYbHGAG5ijeL3yW5SKYAfMNwtme5ELPeGNPhNyKBPGTONMg@mail.gmail.com>
在 2012年3月6日 下午12:16,Jiang Xin <worldhello.net@gmail.com> 写道:
Show 17 quoted lines
>
> /*
>  * 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. Append the output joint string to strbuf 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 +#define MAX_L10N_LIST_ITEMS_COUNT 8

Show 8 quoted lines
> 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*));
+    else if (count >= MAX_L10N_LIST_ITEMS_COUNT)
+        itemlist = xrealloc(itemlist, (count +
MAX_L10N_LIST_ITEMS_COUNT) * sizeof(char*));
-    if(item != NULL && count < MAX_L10N_LIST_ITEMS_COUNT )
+    if (item != NULL)
Show 12 quoted lines
>        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, %s"), itemlist[i], "");
Show 22 quoted lines
>            }
>            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);
> ...
Previous: Jiang Xin
Message 10 of 10 in “i18n: Not add stripped contents for translation”
  1. i18n: Not add stripped contents for translationJiang Xin, Mar 5, 2012
  2. Junio C HamanoMar 5, 2012
  3. Jiang XinMar 5, 2012
  4. Junio C HamanoMar 5, 2012
  5. Jens LehmannMar 5, 2012
  6. Junio C HamanoMar 5, 2012
  7. Jiang XinMar 6, 2012
  8. Junio C HamanoMar 6, 2012
  9. Jiang XinMar 6, 2012
  10. Jiang XinMar 6, 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.