Skip to content

Commit ee695f7

Browse files
committed
patch 7.4.2152
Problem: No proper translation of messages with a count. Solution: Use ngettext(). (Sergey Alyoshin)
1 parent cf25fdb commit ee695f7

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

src/evalfunc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,7 @@ f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
34483448
char_u *r;
34493449
int len;
34503450
char *txt;
3451+
long count;
34513452
#endif
34523453

34533454
rettv->v_type = VAR_STRING;
@@ -3478,14 +3479,15 @@ f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
34783479
s = skipwhite(s + 1);
34793480
}
34803481
}
3481-
txt = _("+-%s%3ld lines: ");
3482+
count = (long)(foldend - foldstart + 1);
3483+
txt = ngettext("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
34823484
r = alloc((unsigned)(STRLEN(txt)
34833485
+ STRLEN(dashes) /* for %s */
34843486
+ 20 /* for %3ld */
34853487
+ STRLEN(s))); /* concatenated */
34863488
if (r != NULL)
34873489
{
3488-
sprintf((char *)r, txt, dashes, (long)(foldend - foldstart + 1));
3490+
sprintf((char *)r, txt, dashes, count);
34893491
len = (int)STRLEN(r);
34903492
STRCAT(r, s);
34913493
/* remove 'foldmarker' and 'commentstring' */
@@ -3505,7 +3507,7 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
35053507
#ifdef FEAT_FOLDING
35063508
linenr_T lnum;
35073509
char_u *text;
3508-
char_u buf[51];
3510+
char_u buf[FOLD_TEXT_LEN];
35093511
foldinfo_T foldinfo;
35103512
int fold_count;
35113513
#endif
@@ -3520,8 +3522,7 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
35203522
fold_count = foldedCount(curwin, lnum, &foldinfo);
35213523
if (fold_count > 0)
35223524
{
3523-
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
3524-
&foldinfo, buf);
3525+
text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf);
35253526
if (text == buf)
35263527
text = vim_strsave(text);
35273528
rettv->vval.v_string = text;

src/fold.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,8 @@ foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
18531853
/* get_foldtext() {{{2 */
18541854
/*
18551855
* Return the text for a closed fold at line "lnum", with last line "lnume".
1856-
* When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the
1857-
* result is in allocated memory.
1856+
* When 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]".
1857+
* Otherwise the result is in allocated memory.
18581858
*/
18591859
char_u *
18601860
get_foldtext(
@@ -1960,8 +1960,12 @@ get_foldtext(
19601960
if (text == NULL)
19611961
#endif
19621962
{
1963-
sprintf((char *)buf, _("+--%3ld lines folded "),
1964-
(long)(lnume - lnum + 1));
1963+
long count = (long)(lnume - lnum + 1);
1964+
1965+
vim_snprintf((char *)buf, FOLD_TEXT_LEN,
1966+
ngettext("+--%3ld line folded ",
1967+
"+--%3ld lines folded ", count),
1968+
count);
19651969
text = buf;
19661970
}
19671971
return text;

src/os_win32.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,15 @@ vimLoadLib(char *name)
472472
# endif
473473
/* Dummy functions */
474474
static char *null_libintl_gettext(const char *);
475+
static char *null_libintl_ngettext(const char *, const char *, unsigned long n);
475476
static char *null_libintl_textdomain(const char *);
476477
static char *null_libintl_bindtextdomain(const char *, const char *);
477478
static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
478479

479480
static HINSTANCE hLibintlDLL = NULL;
480481
char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
482+
char *(*dyn_libintl_ngettext)(const char *, const char *, unsigned long n)
483+
= null_libintl_ngettext;
481484
char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
482485
char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
483486
= null_libintl_bindtextdomain;
@@ -495,6 +498,7 @@ dyn_libintl_init(void)
495498
} libintl_entry[] =
496499
{
497500
{"gettext", (FARPROC*)&dyn_libintl_gettext},
501+
{"ngettext", (FARPROC*)&dyn_libintl_ngettext},
498502
{"textdomain", (FARPROC*)&dyn_libintl_textdomain},
499503
{"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain},
500504
{NULL, NULL}
@@ -553,6 +557,7 @@ dyn_libintl_end(void)
553557
FreeLibrary(hLibintlDLL);
554558
hLibintlDLL = NULL;
555559
dyn_libintl_gettext = null_libintl_gettext;
560+
dyn_libintl_ngettext = null_libintl_ngettext;
556561
dyn_libintl_textdomain = null_libintl_textdomain;
557562
dyn_libintl_bindtextdomain = null_libintl_bindtextdomain;
558563
dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset;
@@ -565,6 +570,16 @@ null_libintl_gettext(const char *msgid)
565570
return (char*)msgid;
566571
}
567572

573+
/*ARGSUSED*/
574+
static char *
575+
null_libintl_ngettext(
576+
const char *msgid,
577+
const char *msgid_plural,
578+
unsigned long n)
579+
{
580+
return n == 1 ? msgid : msgid_plural;
581+
}
582+
568583
/*ARGSUSED*/
569584
static char *
570585
null_libintl_bindtextdomain(const char *domainname, const char *dirname)

src/screen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ fold_line(
24242424
linenr_T lnum,
24252425
int row)
24262426
{
2427-
char_u buf[51];
2427+
char_u buf[FOLD_TEXT_LEN];
24282428
pos_T *top, *bot;
24292429
linenr_T lnume = lnum + fold_count - 1;
24302430
int len;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2152,
766768
/**/
767769
2151,
768770
/**/

src/vim.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
561561
# endif
562562
/* These are in os_win32.c */
563563
extern char *(*dyn_libintl_gettext)(const char *msgid);
564+
extern char *(*dyn_libintl_ngettext)(const char *msgid, const char *msgid_plural, unsigned long n);
564565
extern char *(*dyn_libintl_bindtextdomain)(const char *domainname, const char *dirname);
565566
extern char *(*dyn_libintl_bind_textdomain_codeset)(const char *domainname, const char *codeset);
566567
extern char *(*dyn_libintl_textdomain)(const char *domainname);
@@ -574,6 +575,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
574575
#ifdef FEAT_GETTEXT
575576
# ifdef DYNAMIC_GETTEXT
576577
# define _(x) (*dyn_libintl_gettext)((char *)(x))
578+
# define ngettext(x, xs, n) (*dyn_libintl_ngettext)((char *)(x), (char *)(xs), (n))
577579
# define N_(x) x
578580
# define bindtextdomain(domain, dir) (*dyn_libintl_bindtextdomain)((domain), (dir))
579581
# define bind_textdomain_codeset(domain, codeset) (*dyn_libintl_bind_textdomain_codeset)((domain), (codeset))
@@ -592,6 +594,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
592594
# endif
593595
#else
594596
# define _(x) ((char *)(x))
597+
# define ngettext(x, xs, n) (((n) == 1) ? (char *)(x) : (char *)(xs))
595598
# define N_(x) x
596599
# ifdef bindtextdomain
597600
# undef bindtextdomain
@@ -1501,6 +1504,8 @@ typedef UINT32_TYPEDEF UINT32_T;
15011504
# define MSG_BUF_CLEN MSG_BUF_LEN /* cell length */
15021505
#endif
15031506

1507+
#define FOLD_TEXT_LEN 51 /* buffer size for get_foldtext() */
1508+
15041509
/* Size of the buffer used for tgetent(). Unfortunately this is largely
15051510
* undocumented, some systems use 1024. Using a buffer that is too small
15061511
* causes a buffer overrun and a crash. Use the maximum known value to stay

0 commit comments

Comments
 (0)