]> granicus.if.org Git - vim/commitdiff
patch 7.4.2152 v7.4.2152
authorBram Moolenaar <Bram@vim.org>
Wed, 3 Aug 2016 20:08:45 +0000 (22:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 3 Aug 2016 20:08:45 +0000 (22:08 +0200)
Problem:    No proper translation of messages with a count.
Solution:   Use ngettext(). (Sergey Alyoshin)

src/evalfunc.c
src/fold.c
src/os_win32.c
src/screen.c
src/version.c
src/vim.h

index 68a8b16414ed0c5c344bde67b9c5025d534e7f27..b6f05b14cb46a793980f81eff36db051a9cdf51b 100644 (file)
@@ -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;
index 35ceceb4ad106ae9c5ff243c16d6ddbed6ab302b..1eaad192b27a65abb4cf7a5a929183158f5a0937 100644 (file)
@@ -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;
index 54f2e887fba48ff0374be654484c0c69e4ef7801..9fe43218d2c84db440f7578a4de756f182b470a5 100644 (file)
@@ -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;
@@ -565,6 +570,16 @@ null_libintl_gettext(const char *msgid)
     return (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)
index b16bd87c7c46a4ce2c37ed13ef8e7954492565b3..f8d283fa2dfe7d8282df7f8a7ea6bfde2ef30ed2 100644 (file)
@@ -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;
index 9af79c6b7e7b78b2a367d716723628a64001531c..e69b355c5868c93c2621c041e3c28b71506fbc70 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2152,
 /**/
     2151,
 /**/
index 18c3ff8507456ce14f8d3393df99ccbc23261af0..398fcc548f9124f7242a4917d912ed0fafae7d82 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -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