[PATCH] Add L10N percentages to translation strings.
"Kevin J. McCarthy" <[email protected]> Fri, 1 May 2026 12:47:11 +0800
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <[email protected]> |
From: Kevin McCarthy <[email protected]> This currently applies to the progress bar, the status bar, and the pager. This is based on Emir SARI's patch sent to mutt-po. --- curs_lib.c | 22 +++++++++++++++++++--- muttlib.c | 16 ++++++++++++++++ pager.c | 6 ++++-- protos.h | 2 ++ status.c | 2 +- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index c1eb7bc6..15b53cad 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -724,6 +724,7 @@ void mutt_progress_update(progress_t *progress, long pos, int percent) short update = 0; struct timeval tv = { 0, 0 }; unsigned long long now_millis = 0; + BUFFER *messagefmt = NULL; if (option(OPTNOCURSES)) return; @@ -768,19 +769,34 @@ void mutt_progress_update(progress_t *progress, long pos, int percent) if (now_millis) progress->timestamp_millis = now_millis; + messagefmt = mutt_buffer_pool_get(); + mutt_buffer_strcpy(messagefmt, "%s %s"); if (progress->size > 0) { - mutt_message("%s %s/%s (%d%%)", progress->msg, posstr, progress->sizestr, + mutt_buffer_addstr(messagefmt, "/%s ("); + mutt_buffer_addstr(messagefmt, mutt_l10n_percentage()); + mutt_buffer_addstr(messagefmt, ")"); + mutt_message(mutt_b2s(messagefmt), progress->msg, posstr, + progress->sizestr, percent > 0 ? percent : (int) (100.0 * (double) progress->pos / progress->size)); } else { if (percent > 0) - mutt_message("%s %s (%d%%)", progress->msg, posstr, percent); + { + mutt_buffer_addstr(messagefmt, " ("); + mutt_buffer_addstr(messagefmt, mutt_l10n_percentage()); + mutt_buffer_addstr(messagefmt, ")"); + mutt_message(mutt_b2s(messagefmt), progress->msg, posstr, + percent); + } else - mutt_message("%s %s", progress->msg, posstr); + { + mutt_message(mutt_b2s(messagefmt), progress->msg, posstr); + } } + mutt_buffer_pool_release (&messagefmt); } out: diff --git a/muttlib.c b/muttlib.c index 59a48378..3abf11a1 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1212,6 +1212,22 @@ void mutt_buffer_sanitize_filename(BUFFER *d, const char *f, int flags) } } +/* L10N: + * A percentage value, for example 32%. This is used in + * the progress bar, pager position, and status bar. + * Note the %d is the number and %% is a percentage sign. + * You can reverse the order and/or substitute a different symbol + * that your locale uses, for example: + * "%%%d" which would generate "%32" + * "%d %%" which would generate "32 %" + */ +static const char *localized_percentage = N_("%d%%"); + +const char *mutt_l10n_percentage(void) +{ + return _(localized_percentage); +} + void mutt_expand_file_fmt(BUFFER *dest, const char *fmt, const char *src) { BUFFER *tmp; diff --git a/pager.c b/pager.c index a9c30dbd..e2e16ae9 100644 --- a/pager.c +++ b/pager.c @@ -2007,13 +2007,15 @@ static void pager_menu_redraw(MUTTMENU *pager_menu) if (pager_menu->redraw & REDRAW_STATUS) { struct hdr_format_info hfi; - char pager_progress_str[4]; + char pager_progress_str[20]; hfi.ctx = Context; hfi.pager_progress = pager_progress_str; if (rd->last_pos < rd->sb.st_size - 1) - snprintf(pager_progress_str, sizeof(pager_progress_str), OFF_T_FMT "%%", (100 * rd->last_offset / rd->sb.st_size)); + snprintf(pager_progress_str, sizeof(pager_progress_str), + mutt_l10n_percentage(), + (int) (100 * rd->last_offset / rd->sb.st_size)); else strfcpy(pager_progress_str, (rd->topline == 0) ? "all" : "end", sizeof(pager_progress_str)); diff --git a/protos.h b/protos.h index e5f115f8..b2f9adb4 100644 --- a/protos.h +++ b/protos.h @@ -168,6 +168,8 @@ const char *mutt_make_version(void); const char *mutt_fqdn(short); +const char *mutt_l10n_percentage(void); + group_t *mutt_pattern_group(const char *); REGEXP *mutt_compile_regexp(const char *, int); diff --git a/status.c b/status.c index 761cc2f2..4cb32a89 100644 --- a/status.c +++ b/status.c @@ -225,7 +225,7 @@ status_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const else { count = (100 * (menu->top + menu->pagelen)) / menu->max; - snprintf(tmp, sizeof(tmp), "%d%%", count); + snprintf(tmp, sizeof(tmp), mutt_l10n_percentage(), count); cp = tmp; } snprintf(fmt, sizeof(fmt), "%%%ss", prefix); -- 2.54.0