# HG changeset patch # User Christian Brabandt # Date 1470255306 -7200 # Node ID a990e7ed260b22fbf85a1c07c5b4ceaffd97267a # Parent bba3d9fa5a35e8f005c93fe8b6fa1f9bed8777a4 commit https://github.com/vim/vim/commit/ee695f787ade7fd88fc5f5497553d95c0c3645b5 Author: Bram Moolenaar Date: Wed Aug 3 22:08:45 2016 +0200 patch 7.4.2152 Problem: No proper translation of messages with a count. Solution: Use ngettext(). (Sergey Alyoshin) diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -3448,6 +3448,7 @@ f_foldtext(typval_T *argvars UNUSED, typ char_u *r; int len; char *txt; + long count; #endif rettv->v_type = VAR_STRING; @@ -3478,14 +3479,15 @@ f_foldtext(typval_T *argvars UNUSED, typ s = skipwhite(s + 1); } } - txt = _("+-%s%3ld lines: "); + 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, (long)(foldend - foldstart + 1)); + sprintf((char *)r, txt, dashes, count); len = (int)STRLEN(r); STRCAT(r, s); /* remove 'foldmarker' and 'commentstring' */ @@ -3505,7 +3507,7 @@ f_foldtextresult(typval_T *argvars UNUSE #ifdef FEAT_FOLDING linenr_T lnum; char_u *text; - char_u buf[51]; + char_u buf[FOLD_TEXT_LEN]; foldinfo_T foldinfo; int fold_count; #endif @@ -3520,8 +3522,7 @@ f_foldtextresult(typval_T *argvars UNUSE fold_count = foldedCount(curwin, lnum, &foldinfo); if (fold_count > 0) { - text = get_foldtext(curwin, lnum, lnum + fold_count - 1, - &foldinfo, buf); + text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf); if (text == buf) text = vim_strsave(text); rettv->vval.v_string = text; diff --git a/src/fold.c b/src/fold.c --- a/src/fold.c +++ b/src/fold.c @@ -1853,8 +1853,8 @@ foldDelMarker(linenr_T lnum, char_u *mar /* 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. + * 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,8 +1960,12 @@ get_foldtext( if (text == NULL) #endif { - sprintf((char *)buf, _("+--%3ld lines folded "), - (long)(lnume - lnum + 1)); + 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; diff --git a/src/os_win32.c b/src/os_win32.c --- a/src/os_win32.c +++ b/src/os_win32.c @@ -472,12 +472,15 @@ vimLoadLib(char *name) # 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,6 +498,7 @@ dyn_libintl_init(void) } 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,6 +557,7 @@ dyn_libintl_end(void) 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; @@ -567,6 +572,16 @@ null_libintl_gettext(const char *msgid) /*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) { return NULL; diff --git a/src/screen.c b/src/screen.c --- a/src/screen.c +++ b/src/screen.c @@ -2424,7 +2424,7 @@ fold_line( linenr_T lnum, int row) { - char_u buf[51]; + char_u buf[FOLD_TEXT_LEN]; pos_T *top, *bot; linenr_T lnume = lnum + fold_count - 1; int len; diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2152, +/**/ 2151, /**/ 2150, diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -561,6 +561,7 @@ typedef unsigned long u8char_T; /* l # 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,6 +575,7 @@ extern char *(*dyn_libintl_textdomain)(c #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,6 +594,7 @@ extern char *(*dyn_libintl_textdomain)(c # 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,6 +1504,8 @@ typedef UINT32_TYPEDEF UINT32_T; # 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