To: vim_dev@googlegroups.com Subject: Patch 7.4.2152 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2152 Problem: No proper translation of messages with a count. Solution: Use ngettext(). (Sergey Alyoshin) Files: src/evalfunc.c, src/fold.c, src/os_win32.c, src/screen.c, src/vim.h *** ../vim-7.4.2151/src/evalfunc.c 2016-08-01 15:40:24.179878441 +0200 --- src/evalfunc.c 2016-08-03 21:49:31.786227537 +0200 *************** *** 3448,3453 **** --- 3448,3454 ---- char_u *r; int len; char *txt; + long count; #endif rettv->v_type = VAR_STRING; *************** *** 3478,3491 **** s = skipwhite(s + 1); } } ! txt = _("+-%s%3ld lines: "); r = alloc((unsigned)(STRLEN(txt) + STRLEN(dashes) /* for %s */ + 20 /* for %3ld */ + STRLEN(s))); /* concatenated */ if (r != NULL) { ! sprintf((char *)r, txt, dashes, (long)(foldend - foldstart + 1)); len = (int)STRLEN(r); STRCAT(r, s); /* remove 'foldmarker' and 'commentstring' */ --- 3479,3493 ---- s = skipwhite(s + 1); } } ! count = (long)(foldend - foldstart + 1); ! txt = ngettext("+-%s%3ld line: ", "+-%s%3ld lines: ", count); r = alloc((unsigned)(STRLEN(txt) + STRLEN(dashes) /* for %s */ + 20 /* for %3ld */ + STRLEN(s))); /* concatenated */ if (r != NULL) { ! sprintf((char *)r, txt, dashes, count); len = (int)STRLEN(r); STRCAT(r, s); /* remove 'foldmarker' and 'commentstring' */ *************** *** 3505,3511 **** #ifdef FEAT_FOLDING linenr_T lnum; char_u *text; ! char_u buf[51]; foldinfo_T foldinfo; int fold_count; #endif --- 3507,3513 ---- #ifdef FEAT_FOLDING linenr_T lnum; char_u *text; ! char_u buf[FOLD_TEXT_LEN]; foldinfo_T foldinfo; int fold_count; #endif *************** *** 3520,3527 **** fold_count = foldedCount(curwin, lnum, &foldinfo); if (fold_count > 0) { ! text = get_foldtext(curwin, lnum, lnum + fold_count - 1, ! &foldinfo, buf); if (text == buf) text = vim_strsave(text); rettv->vval.v_string = text; --- 3522,3528 ---- fold_count = foldedCount(curwin, lnum, &foldinfo); if (fold_count > 0) { ! text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf); if (text == buf) text = vim_strsave(text); rettv->vval.v_string = text; *** ../vim-7.4.2151/src/fold.c 2016-07-01 18:16:47.493936250 +0200 --- src/fold.c 2016-08-03 21:49:04.982474748 +0200 *************** *** 1853,1860 **** /* get_foldtext() {{{2 */ /* * Return the text for a closed fold at line "lnum", with last line "lnume". ! * When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the ! * result is in allocated memory. */ char_u * get_foldtext( --- 1853,1860 ---- /* get_foldtext() {{{2 */ /* * Return the text for a closed fold at line "lnum", with last line "lnume". ! * When 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]". ! * Otherwise the result is in allocated memory. */ char_u * get_foldtext( *************** *** 1960,1967 **** if (text == NULL) #endif { ! sprintf((char *)buf, _("+--%3ld lines folded "), ! (long)(lnume - lnum + 1)); text = buf; } return text; --- 1960,1971 ---- if (text == NULL) #endif { ! long count = (long)(lnume - lnum + 1); ! ! vim_snprintf((char *)buf, FOLD_TEXT_LEN, ! ngettext("+--%3ld line folded ", ! "+--%3ld lines folded ", count), ! count); text = buf; } return text; *** ../vim-7.4.2151/src/os_win32.c 2016-08-03 20:54:53.360238783 +0200 --- src/os_win32.c 2016-08-03 21:54:38.807398375 +0200 *************** *** 472,483 **** --- 472,486 ---- # endif /* Dummy functions */ static char *null_libintl_gettext(const char *); + static char *null_libintl_ngettext(const char *, const char *, unsigned long n); static char *null_libintl_textdomain(const char *); static char *null_libintl_bindtextdomain(const char *, const char *); static char *null_libintl_bind_textdomain_codeset(const char *, const char *); static HINSTANCE hLibintlDLL = NULL; char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext; + char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n) + = null_libintl_ngettext; char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain; char *(*dyn_libintl_bindtextdomain)(const char *, const char *) = null_libintl_bindtextdomain; *************** *** 495,500 **** --- 498,504 ---- } libintl_entry[] = { {"gettext", (FARPROC*)&dyn_libintl_gettext}, + {"ngettext", (FARPROC*)&dyn_libintl_ngettext}, {"textdomain", (FARPROC*)&dyn_libintl_textdomain}, {"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain}, {NULL, NULL} *************** *** 553,558 **** --- 557,563 ---- FreeLibrary(hLibintlDLL); hLibintlDLL = NULL; dyn_libintl_gettext = null_libintl_gettext; + dyn_libintl_ngettext = null_libintl_ngettext; dyn_libintl_textdomain = null_libintl_textdomain; dyn_libintl_bindtextdomain = null_libintl_bindtextdomain; dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; *************** *** 566,571 **** --- 571,586 ---- } /*ARGSUSED*/ + static char * + null_libintl_ngettext( + const char *msgid, + const char *msgid_plural, + unsigned long n) + { + return n == 1 ? msgid : msgid_plural; + } + + /*ARGSUSED*/ static char * null_libintl_bindtextdomain(const char *domainname, const char *dirname) { *** ../vim-7.4.2151/src/screen.c 2016-07-27 23:26:00.782222261 +0200 --- src/screen.c 2016-08-03 21:49:44.262112484 +0200 *************** *** 2424,2430 **** linenr_T lnum, int row) { ! char_u buf[51]; pos_T *top, *bot; linenr_T lnume = lnum + fold_count - 1; int len; --- 2424,2430 ---- linenr_T lnum, int row) { ! char_u buf[FOLD_TEXT_LEN]; pos_T *top, *bot; linenr_T lnume = lnum + fold_count - 1; int len; *** ../vim-7.4.2151/src/vim.h 2016-08-01 15:40:24.167878553 +0200 --- src/vim.h 2016-08-03 21:55:55.966688060 +0200 *************** *** 561,566 **** --- 561,567 ---- # endif /* These are in os_win32.c */ extern char *(*dyn_libintl_gettext)(const char *msgid); + extern char *(*dyn_libintl_ngettext)(const char *msgid, const char *msgid_plural, unsigned long n); extern char *(*dyn_libintl_bindtextdomain)(const char *domainname, const char *dirname); extern char *(*dyn_libintl_bind_textdomain_codeset)(const char *domainname, const char *codeset); extern char *(*dyn_libintl_textdomain)(const char *domainname); *************** *** 574,579 **** --- 575,581 ---- #ifdef FEAT_GETTEXT # ifdef DYNAMIC_GETTEXT # define _(x) (*dyn_libintl_gettext)((char *)(x)) + # define ngettext(x, xs, n) (*dyn_libintl_ngettext)((char *)(x), (char *)(xs), (n)) # define N_(x) x # define bindtextdomain(domain, dir) (*dyn_libintl_bindtextdomain)((domain), (dir)) # define bind_textdomain_codeset(domain, codeset) (*dyn_libintl_bind_textdomain_codeset)((domain), (codeset)) *************** *** 592,597 **** --- 594,600 ---- # endif #else # define _(x) ((char *)(x)) + # define ngettext(x, xs, n) (((n) == 1) ? (char *)(x) : (char *)(xs)) # define N_(x) x # ifdef bindtextdomain # undef bindtextdomain *************** *** 1501,1506 **** --- 1504,1511 ---- # define MSG_BUF_CLEN MSG_BUF_LEN /* cell length */ #endif + #define FOLD_TEXT_LEN 51 /* buffer size for get_foldtext() */ + /* Size of the buffer used for tgetent(). Unfortunately this is largely * undocumented, some systems use 1024. Using a buffer that is too small * causes a buffer overrun and a crash. Use the maximum known value to stay *** ../vim-7.4.2151/src/version.c 2016-08-03 21:04:47.858847794 +0200 --- src/version.c 2016-08-03 21:43:27.913586672 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2152, /**/ -- FIRST SOLDIER: So they wouldn't be able to bring a coconut back anyway. SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together? FIRST SOLDIER: No, they'd have to have it on a line. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///