Permalink
Browse files

patch 7.4.2152

Problem:    No proper translation of messages with a count.
Solution:   Use ngettext(). (Sergey Alyoshin)
  • Loading branch information...
1 parent cf25fdb commit ee695f787ade7fd88fc5f5497553d95c0c3645b5 @brammool brammool committed Aug 3, 2016
Showing with 37 additions and 10 deletions.
  1. +6 −5 src/evalfunc.c
  2. +8 −4 src/fold.c
  3. +15 −0 src/os_win32.c
  4. +1 −1 src/screen.c
  5. +2 −0 src/version.c
  6. +5 −0 src/vim.h
View
@@ -3448,6 +3448,7 @@ f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
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, typval_T *rettv)
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 UNUSED, typval_T *rettv)
#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 UNUSED, typval_T *rettv)
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;
View
@@ -1853,8 +1853,8 @@ foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
/* 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;
View
@@ -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;
View
@@ -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;
View
@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2152,
+/**/
2151,
/**/
2150,
View
@@ -561,6 +561,7 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
# 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)(const char *domainname);
#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)(const char *domainname);
# 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

0 comments on commit ee695f7

Please sign in to comment.