]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1497: the ruler percentage can't be localized v9.0.1497
authorEmir SARI <emir_sari@icloud.com>
Sat, 29 Apr 2023 11:09:53 +0000 (12:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 29 Apr 2023 11:09:53 +0000 (12:09 +0100)
Problem:    The ruler percentage can't be localized.
Solution:   Use a string that can be translated. (Emir Sari, closes #12311)

src/buffer.c
src/version.c

index 98cca6ca7c7379cb9c19652da5e5bdd46c61c227..174ca1efb86c63abbdd73c9ec6933ff3861cf57b 100644 (file)
@@ -5231,8 +5231,8 @@ build_stl_str_hl(
 #endif // FEAT_STL_OPT
 
 /*
- * Get relative cursor position in window into "buf[buflen]", in the form 99%,
- * using "Top", "Bot" or "All" when appropriate.
+ * Get relative cursor position in window into "buf[buflen]", in the localized
+ * percentage form like %99, 99%; using "Top", "Bot" or "All" when appropriate.
  */
     void
 get_rel_pos(
@@ -5256,13 +5256,27 @@ get_rel_pos(
     below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1;
     if (below <= 0)
        vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")),
-                                                       (size_t)(buflen - 1));
+                   (size_t)(buflen - 1));
     else if (above <= 0)
        vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1));
     else
-       vim_snprintf((char *)buf, (size_t)buflen, "%2d%%", above > 1000000L
-                                   ? (int)(above / ((above + below) / 100L))
-                                   : (int)(above * 100L / (above + below)));
+    {
+       int perc = (above > 1000000L)
+                       ?  (int)(above / ((above + below) / 100L))
+                       :  (int)(above * 100L / (above + below));
+
+       char *p = (char *)buf;
+       size_t l = buflen;
+       if (perc < 10)
+       {
+           // prepend one space
+           buf[0] = ' ';
+           ++p;
+           --l;
+       }
+       // localized percentage value
+       vim_snprintf(p, l, _("%d%%"), perc);
+    }
 }
 
 /*
index 331d6c99f4e1073c7854f4e7560e68b4573d3d25..7bb63e9546f72a7eae01eed7e69419067d071686 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1497,
 /**/
     1496,
 /**/