summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorEmir SARI <emir_sari@icloud.com>2023-04-29 12:09:53 +0100
committerBram Moolenaar <Bram@vim.org>2023-04-29 12:09:53 +0100
commit971cd2b8bc3e3a7faa886162cd7568938c627882 (patch)
treed80f1e3fe399359e08deede1f8274d1438677f36 /src/buffer.c
parent0b933c331d72f4a378fc30d96a7d16eb1aedd1d4 (diff)
patch 9.0.1497: the ruler percentage can't be localizedv9.0.1497
Problem: The ruler percentage can't be localized. Solution: Use a string that can be translated. (Emir Sari, closes #12311)
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 98cca6ca7c..174ca1efb8 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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);
+ }
}
/*