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)
da6e8919e7
This commit is contained in:
James McCoy
2021-10-23 15:10:28 -04:00
parent 7f4b7320f6
commit 684640f551
7 changed files with 73 additions and 122 deletions

View File

@@ -1016,23 +1016,14 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
errormsg = IObuff; errormsg = IObuff;
} else if (deleted >= p_report) { } else if (deleted >= p_report) {
if (command == DOBUF_UNLOAD) { if (command == DOBUF_UNLOAD) {
if (deleted == 1) { smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", (unsigned long)deleted),
MSG(_("1 buffer unloaded")); deleted);
} else {
smsg(_("%d buffers unloaded"), deleted);
}
} else if (command == DOBUF_DEL) { } else if (command == DOBUF_DEL) {
if (deleted == 1) { smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", (unsigned long)deleted),
MSG(_("1 buffer deleted")); deleted);
} else {
smsg(_("%d buffers deleted"), deleted);
}
} else { } else {
if (deleted == 1) { smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", (unsigned long)deleted),
MSG(_("1 buffer wiped out")); deleted);
} else {
smsg(_("%d buffers wiped out"), deleted);
}
} }
} }
} }
@@ -3103,12 +3094,11 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
vim_snprintf_add((char *)buffer, IOSIZE, "%s", _(no_lines_msg)); vim_snprintf_add((char *)buffer, IOSIZE, "%s", _(no_lines_msg));
} else if (p_ru) { } else if (p_ru) {
// Current line and column are already on the screen -- webb // Current line and column are already on the screen -- webb
if (curbuf->b_ml.ml_line_count == 1) { vim_snprintf_add((char *)buffer, IOSIZE,
vim_snprintf_add((char *)buffer, IOSIZE, _("1 line --%d%%--"), n); NGETTEXT("%" PRId64 " line --%d%%--",
} else { "%" PRId64 " lines --%d%%--",
vim_snprintf_add((char *)buffer, IOSIZE, _("%" PRId64 " lines --%d%%--"), (unsigned long)curbuf->b_ml.ml_line_count),
(int64_t)curbuf->b_ml.ml_line_count, n); (int64_t)curbuf->b_ml.ml_line_count, n);
}
} else { } else {
vim_snprintf_add((char *)buffer, IOSIZE, vim_snprintf_add((char *)buffer, IOSIZE,
_("line %" PRId64 " of %" PRId64 " --%d%%-- col "), _("line %" PRId64 " of %" PRId64 " --%d%%-- col "),

View File

@@ -1015,11 +1015,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
ml_delete(line1 + extra, true); ml_delete(line1 + extra, true);
} }
if (!global_busy && num_lines > p_report) { if (!global_busy && num_lines > p_report) {
if (num_lines == 1) { smsg(NGETTEXT("1 line moved", "%" PRId64 " lines moved", num_lines), (int64_t)num_lines);
MSG(_("1 line moved"));
} else {
smsg(_("%" PRId64 " lines moved"), (int64_t)num_lines);
}
} }
extmark_move_region(curbuf, line1-1, 0, start_byte, extmark_move_region(curbuf, line1-1, 0, start_byte,
@@ -4456,22 +4452,20 @@ bool do_sub_msg(bool count_only)
} else { } else {
*msg_buf = NUL; *msg_buf = NUL;
} }
if (sub_nsubs == 1) {
vim_snprintf_add(msg_buf, sizeof(msg_buf), char *msg_single = count_only
"%s", count_only ? _("1 match") : _("1 substitution")); ? NGETTEXT("%" PRId64 " match on %" PRId64 " line",
} else { "%" PRId64 " matches on %" PRId64 " line", sub_nsubs)
vim_snprintf_add(msg_buf, sizeof(msg_buf), : NGETTEXT("%" PRId64 " substitution on %" PRId64 " line",
count_only ? _("%" PRId64 " matches") "%" PRId64 " substitutions on %" PRId64 " line", sub_nsubs);
: _("%" PRId64 " substitutions"), char *msg_plural = count_only
(int64_t)sub_nsubs); ? NGETTEXT("%" PRId64 " match on %" PRId64 " lines",
} "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs)
if (sub_nlines == 1) { : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines",
vim_snprintf_add(msg_buf, sizeof(msg_buf), "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs);
"%s", _(" on 1 line")); vim_snprintf_add((char *)msg_buf, sizeof(msg_buf),
} else { NGETTEXT(msg_single, msg_plural, sub_nlines),
vim_snprintf_add(msg_buf, sizeof(msg_buf), (int64_t)sub_nsubs, (int64_t)sub_nlines);
_(" on %" PRId64 " lines"), (int64_t)sub_nlines);
}
if (msg((char_u *)msg_buf)) { if (msg((char_u *)msg_buf)) {
// save message to display it after redraw // save message to display it after redraw
set_keep_msg((char_u *)msg_buf, 0); set_keep_msg((char_u *)msg_buf, 0);

View File

@@ -5116,23 +5116,16 @@ static int check_more(int message, bool forceit)
if ((p_confirm || cmdmod.confirm) && curbuf->b_fname != NULL) { if ((p_confirm || cmdmod.confirm) && curbuf->b_fname != NULL) {
char_u buff[DIALOG_MSG_SIZE]; char_u buff[DIALOG_MSG_SIZE];
if (n == 1) { vim_snprintf((char *)buff, DIALOG_MSG_SIZE,
STRLCPY(buff, _("1 more file to edit. Quit anyway?"), NGETTEXT("%d more file to edit. Quit anyway?",
DIALOG_MSG_SIZE); "%d more files to edit. Quit anyway?", (unsigned long)n), n);
} else {
vim_snprintf((char *)buff, DIALOG_MSG_SIZE,
_("%d more files to edit. Quit anyway?"), n);
}
if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) { if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) {
return OK; return OK;
} }
return FAIL; return FAIL;
} }
if (n == 1) { EMSGN(NGETTEXT("E173: %d more file to edit",
EMSG(_("E173: 1 more file to edit")); "E173: %d more files to edit", (unsigned long)n), n);
} else {
EMSGN(_("E173: %" PRId64 " more files to edit"), n);
}
quitmore = 2; // next try to quit is allowed quitmore = 2; // next try to quit is allowed
} }
return FAIL; return FAIL;

View File

@@ -3849,20 +3849,16 @@ void msg_add_lines(int insert_space, long lnum, off_T nchars)
*p++ = ' '; *p++ = ' ';
} }
if (shortmess(SHM_LINES)) { if (shortmess(SHM_LINES)) {
sprintf((char *)p, "%" PRId64 "L, %" PRId64 "C", vim_snprintf((char *)p, IOSIZE - (p - IObuff), "%" PRId64 "L, %" PRId64 "C",
(int64_t)lnum, (int64_t)nchars); (int64_t)lnum, (int64_t)nchars);
} else { } else {
if (lnum == 1) { vim_snprintf((char *)p, IOSIZE - (p - IObuff),
STRCPY(p, _("1 line, ")); NGETTEXT("%" PRId64 " line, ", "%" PRId64 " lines, ", lnum),
} else { (int64_t)lnum);
sprintf((char *)p, _("%" PRId64 " lines, "), (int64_t)lnum);
}
p += STRLEN(p); p += STRLEN(p);
if (nchars == 1) { vim_snprintf((char *)p, IOSIZE - (p - IObuff),
STRCPY(p, _("1 character")); NGETTEXT("%" PRId64 " character", "%" PRId64 " characters", nchars),
} else { (int64_t)nchars);
sprintf((char *)p, _("%" PRId64 " characters"), (int64_t)nchars);
}
} }
} }

View File

@@ -10,7 +10,7 @@
# else # else
# define N_(x) x # define N_(x) x
# endif # 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 // On a Mac, gettext's libintl.h defines "setlocale" to be replaced by
// "libintl_setlocal" which leads to wrong return values. #9789 // "libintl_setlocal" which leads to wrong return values. #9789
# if defined(__APPLE__) && defined(setlocale) # if defined(__APPLE__) && defined(setlocale)

View File

@@ -686,20 +686,14 @@ void msgmore(long n)
} }
if (pn > p_report) { if (pn > p_report) {
if (pn == 1) { if (n > 0) {
if (n > 0) { vim_snprintf(msg_buf, MSG_BUF_LEN,
STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN); NGETTEXT("%ld more line", "%ld more lines", pn),
} else { pn);
STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
}
} else { } else {
if (n > 0) { vim_snprintf(msg_buf, MSG_BUF_LEN,
vim_snprintf(msg_buf, MSG_BUF_LEN, NGETTEXT("%ld line less", "%ld fewer lines", pn),
_("%" PRId64 " more lines"), (int64_t)pn); pn);
} else {
vim_snprintf(msg_buf, MSG_BUF_LEN,
_("%" PRId64 " fewer lines"), (int64_t)pn);
}
} }
if (got_int) { if (got_int) {
xstrlcat(msg_buf, _(" (Interrupted)"), MSG_BUF_LEN); xstrlcat(msg_buf, _(" (Interrupted)"), MSG_BUF_LEN);

View File

@@ -210,7 +210,6 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
{ {
long i; long i;
int first_char; int first_char;
char_u *s;
int block_col = 0; int block_col = 0;
if (u_save((linenr_T)(oap->start.lnum - 1), 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(); foldOpenCursor();
if (oap->line_count > p_report) { if (oap->line_count > p_report) {
char *op;
if (oap->op_type == OP_RSHIFT) { if (oap->op_type == OP_RSHIFT) {
s = (char_u *)">"; op = ">";
} else { } else {
s = (char_u *)"<"; op = "<";
}
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);
}
} }
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); 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) { if (oap->line_count > p_report) {
i = oap->line_count - (i + 1); i = oap->line_count - (i + 1);
if (i == 1) { smsg(NGETTEXT("%" PRId64 " line indented ",
MSG(_("1 line indented ")); "%" PRId64 " lines indented ", i),
} else { (int64_t)i);
smsg(_("%" PRId64 " lines indented "), (int64_t)i);
}
} }
// set '[ and '] marks // set '[ and '] marks
curbuf->b_op_start = oap->start; curbuf->b_op_start = oap->start;
@@ -2073,11 +2064,9 @@ void op_tilde(oparg_T *oap)
curbuf->b_op_end = oap->end; curbuf->b_op_end = oap->end;
if (oap->line_count > p_report) { if (oap->line_count > p_report) {
if (oap->line_count == 1) { smsg(NGETTEXT("%" PRId64 " line changed",
MSG(_("1 line changed")); "%" PRId64 " lines changed", oap->line_count),
} else { (int64_t)oap->line_count);
smsg(_("%" PRId64 " lines changed"), (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 // redisplay now, so message is not deleted
update_topline_redraw(); update_topline_redraw();
if (yanklines == 1) { if (yank_type == kMTBlockWise) {
if (yank_type == kMTBlockWise) { smsg(NGETTEXT("block of %" PRId64 " line yanked%s",
smsg(_("block of 1 line yanked%s"), namebuf); "block of %" PRId64 " lines yanked%s", yanklines),
} else {
smsg(_("1 line yanked%s"), namebuf);
}
} else if (yank_type == kMTBlockWise) {
smsg(_("block of %" PRId64 " lines yanked%s"),
(int64_t)yanklines, namebuf); (int64_t)yanklines, namebuf);
} else { } 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 > p_report) {
if (change_cnt == 1) { smsg(NGETTEXT("%" PRId64 " lines changed",
MSG(_("1 line changed")); "%" PRId64 " lines changed", change_cnt),
} else { (int64_t)change_cnt);
smsg(_("%" PRId64 " lines changed"), (int64_t)change_cnt);
}
} }
} }
} }