diff options
author | James McCoy <jamessan@jamessan.com> | 2021-10-23 15:10:28 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2021-11-01 06:40:00 -0400 |
commit | 684640f5518a483cf2bc48efc8f68449379cef69 (patch) | |
tree | a57866f1d9ca7d05e1a3436015d8aaa3c59438e8 | |
parent | 7f4b7320f63eee37841b9b7608495a3f6f9d2fb7 (diff) | |
download | rneovim-684640f5518a483cf2bc48efc8f68449379cef69.tar.gz rneovim-684640f5518a483cf2bc48efc8f68449379cef69.tar.bz2 rneovim-684640f5518a483cf2bc48efc8f68449379cef69.zip |
vim-patch:8.1.0306: plural messages are not translated properly
Problem: Plural messages are not translated properly.
Solution: Add more usage of NGETTEXT(). (Sergey Alyoshin)
https://github.com/vim/vim/commit/da6e8919e75fa8f961d1b805e877c8a92e76dafb
-rw-r--r-- | src/nvim/buffer.c | 32 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 36 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 17 | ||||
-rw-r--r-- | src/nvim/fileio.c | 20 | ||||
-rw-r--r-- | src/nvim/gettext.h | 2 | ||||
-rw-r--r-- | src/nvim/misc1.c | 20 | ||||
-rw-r--r-- | src/nvim/ops.c | 68 |
7 files changed, 73 insertions, 122 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a4c7b1816c..62d41051e0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1016,23 +1016,14 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e errormsg = IObuff; } else if (deleted >= p_report) { if (command == DOBUF_UNLOAD) { - if (deleted == 1) { - MSG(_("1 buffer unloaded")); - } else { - smsg(_("%d buffers unloaded"), deleted); - } + smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", (unsigned long)deleted), + deleted); } else if (command == DOBUF_DEL) { - if (deleted == 1) { - MSG(_("1 buffer deleted")); - } else { - smsg(_("%d buffers deleted"), deleted); - } + smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", (unsigned long)deleted), + deleted); } else { - if (deleted == 1) { - MSG(_("1 buffer wiped out")); - } else { - smsg(_("%d buffers wiped out"), deleted); - } + smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", (unsigned long)deleted), + deleted); } } } @@ -3103,12 +3094,11 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) vim_snprintf_add((char *)buffer, IOSIZE, "%s", _(no_lines_msg)); } else if (p_ru) { // Current line and column are already on the screen -- webb - if (curbuf->b_ml.ml_line_count == 1) { - vim_snprintf_add((char *)buffer, IOSIZE, _("1 line --%d%%--"), n); - } else { - vim_snprintf_add((char *)buffer, IOSIZE, _("%" PRId64 " lines --%d%%--"), - (int64_t)curbuf->b_ml.ml_line_count, n); - } + vim_snprintf_add((char *)buffer, IOSIZE, + NGETTEXT("%" PRId64 " line --%d%%--", + "%" PRId64 " lines --%d%%--", + (unsigned long)curbuf->b_ml.ml_line_count), + (int64_t)curbuf->b_ml.ml_line_count, n); } else { vim_snprintf_add((char *)buffer, IOSIZE, _("line %" PRId64 " of %" PRId64 " --%d%%-- col "), diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 8db1f984ba..b5a3a5fad7 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1015,11 +1015,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) ml_delete(line1 + extra, true); } if (!global_busy && num_lines > p_report) { - if (num_lines == 1) { - MSG(_("1 line moved")); - } else { - smsg(_("%" PRId64 " lines moved"), (int64_t)num_lines); - } + smsg(NGETTEXT("1 line moved", "%" PRId64 " lines moved", num_lines), (int64_t)num_lines); } extmark_move_region(curbuf, line1-1, 0, start_byte, @@ -4456,22 +4452,20 @@ bool do_sub_msg(bool count_only) } else { *msg_buf = NUL; } - if (sub_nsubs == 1) { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - "%s", count_only ? _("1 match") : _("1 substitution")); - } else { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - count_only ? _("%" PRId64 " matches") - : _("%" PRId64 " substitutions"), - (int64_t)sub_nsubs); - } - if (sub_nlines == 1) { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - "%s", _(" on 1 line")); - } else { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - _(" on %" PRId64 " lines"), (int64_t)sub_nlines); - } + + char *msg_single = count_only + ? NGETTEXT("%" PRId64 " match on %" PRId64 " line", + "%" PRId64 " matches on %" PRId64 " line", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " line", + "%" PRId64 " substitutions on %" PRId64 " line", sub_nsubs); + char *msg_plural = count_only + ? NGETTEXT("%" PRId64 " match on %" PRId64 " lines", + "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines", + "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs); + vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), + NGETTEXT(msg_single, msg_plural, sub_nlines), + (int64_t)sub_nsubs, (int64_t)sub_nlines); if (msg((char_u *)msg_buf)) { // save message to display it after redraw set_keep_msg((char_u *)msg_buf, 0); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index f932bbae5f..9412bff2e6 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5116,23 +5116,16 @@ static int check_more(int message, bool forceit) if ((p_confirm || cmdmod.confirm) && curbuf->b_fname != NULL) { char_u buff[DIALOG_MSG_SIZE]; - if (n == 1) { - STRLCPY(buff, _("1 more file to edit. Quit anyway?"), - DIALOG_MSG_SIZE); - } else { - vim_snprintf((char *)buff, DIALOG_MSG_SIZE, - _("%d more files to edit. Quit anyway?"), n); - } + vim_snprintf((char *)buff, DIALOG_MSG_SIZE, + NGETTEXT("%d more file to edit. Quit anyway?", + "%d more files to edit. Quit anyway?", (unsigned long)n), n); if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) { return OK; } return FAIL; } - if (n == 1) { - EMSG(_("E173: 1 more file to edit")); - } else { - EMSGN(_("E173: %" PRId64 " more files to edit"), n); - } + EMSGN(NGETTEXT("E173: %d more file to edit", + "E173: %d more files to edit", (unsigned long)n), n); quitmore = 2; // next try to quit is allowed } return FAIL; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index f7e248dce9..cde6a55199 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3849,20 +3849,16 @@ void msg_add_lines(int insert_space, long lnum, off_T nchars) *p++ = ' '; } if (shortmess(SHM_LINES)) { - sprintf((char *)p, "%" PRId64 "L, %" PRId64 "C", - (int64_t)lnum, (int64_t)nchars); + vim_snprintf((char *)p, IOSIZE - (p - IObuff), "%" PRId64 "L, %" PRId64 "C", + (int64_t)lnum, (int64_t)nchars); } else { - if (lnum == 1) { - STRCPY(p, _("1 line, ")); - } else { - sprintf((char *)p, _("%" PRId64 " lines, "), (int64_t)lnum); - } + vim_snprintf((char *)p, IOSIZE - (p - IObuff), + NGETTEXT("%" PRId64 " line, ", "%" PRId64 " lines, ", lnum), + (int64_t)lnum); p += STRLEN(p); - if (nchars == 1) { - STRCPY(p, _("1 character")); - } else { - sprintf((char *)p, _("%" PRId64 " characters"), (int64_t)nchars); - } + vim_snprintf((char *)p, IOSIZE - (p - IObuff), + NGETTEXT("%" PRId64 " character", "%" PRId64 " characters", nchars), + (int64_t)nchars); } } diff --git a/src/nvim/gettext.h b/src/nvim/gettext.h index 629301e8fe..6d2a55124e 100644 --- a/src/nvim/gettext.h +++ b/src/nvim/gettext.h @@ -10,7 +10,7 @@ # else # define N_(x) x # endif -# define NGETTEXT(x, xs, n) ngettext(x, xs, n) +# define NGETTEXT(x, xs, n) ngettext(x, xs, (unsigned long)n) // On a Mac, gettext's libintl.h defines "setlocale" to be replaced by // "libintl_setlocal" which leads to wrong return values. #9789 # if defined(__APPLE__) && defined(setlocale) diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index f4f2690e47..561bcd4929 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -686,20 +686,14 @@ void msgmore(long n) } if (pn > p_report) { - if (pn == 1) { - if (n > 0) { - STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN); - } else { - STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN); - } + if (n > 0) { + vim_snprintf(msg_buf, MSG_BUF_LEN, + NGETTEXT("%ld more line", "%ld more lines", pn), + pn); } else { - if (n > 0) { - vim_snprintf(msg_buf, MSG_BUF_LEN, - _("%" PRId64 " more lines"), (int64_t)pn); - } else { - vim_snprintf(msg_buf, MSG_BUF_LEN, - _("%" PRId64 " fewer lines"), (int64_t)pn); - } + vim_snprintf(msg_buf, MSG_BUF_LEN, + NGETTEXT("%ld line less", "%ld fewer lines", pn), + pn); } if (got_int) { xstrlcat(msg_buf, _(" (Interrupted)"), MSG_BUF_LEN); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 36a5e1e7e8..d995a2b75b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -210,7 +210,6 @@ void op_shift(oparg_T *oap, int curs_top, int amount) { long i; int first_char; - char_u *s; int block_col = 0; if (u_save((linenr_T)(oap->start.lnum - 1), @@ -249,26 +248,20 @@ void op_shift(oparg_T *oap, int curs_top, int amount) foldOpenCursor(); if (oap->line_count > p_report) { + char *op; if (oap->op_type == OP_RSHIFT) { - s = (char_u *)">"; + op = ">"; } else { - s = (char_u *)"<"; - } - if (oap->line_count == 1) { - if (amount == 1) { - sprintf((char *)IObuff, _("1 line %sed 1 time"), s); - } else { - sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); - } - } else { - if (amount == 1) { - sprintf((char *)IObuff, _("%" PRId64 " lines %sed 1 time"), - (int64_t)oap->line_count, s); - } else { - sprintf((char *)IObuff, _("%" PRId64 " lines %sed %d times"), - (int64_t)oap->line_count, s, amount); - } + op = "<"; } + + char *msg_line_single = NGETTEXT("%" PRId64 " line %sed %d time", + "%" PRId64 " line %sed %d times", amount); + char *msg_line_plural = NGETTEXT("%" PRId64 " lines %sed %d time", + "%" PRId64 " lines %sed %d times", amount); + vim_snprintf((char *)IObuff, IOSIZE, + NGETTEXT(msg_line_single, msg_line_plural, oap->line_count), + (int64_t)oap->line_count, op, amount); msg_attr_keep(IObuff, 0, true, false); } @@ -695,11 +688,9 @@ void op_reindent(oparg_T *oap, Indenter how) if (oap->line_count > p_report) { i = oap->line_count - (i + 1); - if (i == 1) { - MSG(_("1 line indented ")); - } else { - smsg(_("%" PRId64 " lines indented "), (int64_t)i); - } + smsg(NGETTEXT("%" PRId64 " line indented ", + "%" PRId64 " lines indented ", i), + (int64_t)i); } // set '[ and '] marks curbuf->b_op_start = oap->start; @@ -2073,11 +2064,9 @@ void op_tilde(oparg_T *oap) curbuf->b_op_end = oap->end; if (oap->line_count > p_report) { - if (oap->line_count == 1) { - MSG(_("1 line changed")); - } else { - smsg(_("%" PRId64 " lines changed"), (int64_t)oap->line_count); - } + smsg(NGETTEXT("%" PRId64 " line changed", + "%" PRId64 " lines changed", oap->line_count), + (int64_t)oap->line_count); } } @@ -2732,17 +2721,14 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // redisplay now, so message is not deleted update_topline_redraw(); - if (yanklines == 1) { - if (yank_type == kMTBlockWise) { - smsg(_("block of 1 line yanked%s"), namebuf); - } else { - smsg(_("1 line yanked%s"), namebuf); - } - } else if (yank_type == kMTBlockWise) { - smsg(_("block of %" PRId64 " lines yanked%s"), + if (yank_type == kMTBlockWise) { + smsg(NGETTEXT("block of %" PRId64 " line yanked%s", + "block of %" PRId64 " lines yanked%s", yanklines), (int64_t)yanklines, namebuf); } else { - smsg(_("%" PRId64 " lines yanked%s"), (int64_t)yanklines, namebuf); + smsg(NGETTEXT("%" PRId64 " line yanked%s", + "%" PRId64 " lines yanked%s", yanklines), + (int64_t)yanklines, namebuf); } } } @@ -4808,11 +4794,9 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) } if (change_cnt > p_report) { - if (change_cnt == 1) { - MSG(_("1 line changed")); - } else { - smsg(_("%" PRId64 " lines changed"), (int64_t)change_cnt); - } + smsg(NGETTEXT("%" PRId64 " lines changed", + "%" PRId64 " lines changed", change_cnt), + (int64_t)change_cnt); } } } |