printf: simplify conversion specifiers

This is another case where we can don't need to use complicated
formatting specifiers. There is also no need to use `wgettext_fmt` for
messages which don't contain any localizable parts.

The instances using `sprintf` could be kept as is, but I think it's
better to keep the width computation at the place where it can sensibly
be done, even though it is not done correctly at the moment because it
does not use grapheme widths.

Removing complicated conversion specifiers from localized messages helps
with the transition to Fluent.

Closes #12119
This commit is contained in:
Daniel Rainer
2025-11-28 01:34:52 +01:00
committed by danielrainer
parent 8a75bccf00
commit 5210c16bfa
10 changed files with 11 additions and 35 deletions

View File

@@ -155,10 +155,6 @@ msgstr ""
msgid "%s, version %s\n"
msgstr "%s, version %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr ""
#, c-format
msgid "%s: %s\n"
msgstr ""

View File

@@ -153,10 +153,6 @@ msgstr ""
msgid "%s, version %s\n"
msgstr "%s, version %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr ""
#, c-format
msgid "%s: %s\n"
msgstr ""

View File

@@ -284,10 +284,6 @@ msgstr "%s, version %s"
msgid "%s, version %s\n"
msgstr "%s, version %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr "%s : %*s\n"
#, c-format
msgid "%s: %s\n"
msgstr "%s : %s\n"

View File

@@ -149,10 +149,6 @@ msgstr ""
msgid "%s, version %s\n"
msgstr "%s, wersja %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr ""
#, c-format
msgid "%s: %s\n"
msgstr ""

View File

@@ -154,10 +154,6 @@ msgstr ""
msgid "%s, version %s\n"
msgstr "%s, versão %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr ""
#, c-format
msgid "%s: %s\n"
msgstr ""

View File

@@ -150,10 +150,6 @@ msgstr ""
msgid "%s, version %s\n"
msgstr "%s, version %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr ""
#, c-format
msgid "%s: %s\n"
msgstr ""

View File

@@ -176,10 +176,6 @@ msgstr "%s版本 %s"
msgid "%s, version %s\n"
msgstr "%s版本 %s\n"
#, c-format
msgid "%s: %*s\n"
msgstr "%s: %*s\n"
#, c-format
msgid "%s: %s\n"
msgstr "%s: %s\n"

View File

@@ -149,10 +149,6 @@ msgstr "%s%s 版"
msgid "%s, version %s\n"
msgstr "%s%s 版\n"
#, c-format
msgid "%s: %*s\n"
msgstr "%s%*s\n"
#, c-format
msgid "%s: %s\n"
msgstr "%s%s\n"

View File

@@ -353,8 +353,12 @@ fn abbr_add(opts: &Options, streams: &mut IoStreams) -> BuiltinResult {
if let Some(offset) = error.offset() {
streams
.err
.append(wgettext_fmt!("%s: %s\n", CMD, regex_pattern.as_utfstr()));
streams.err.append(sprintf!("%s: %*s\n", CMD, offset, "^"));
.append(sprintf!("%s: %s\n", CMD, regex_pattern.as_utfstr()));
// TODO: This is misaligned if `regex_pattern` contains characters which are not
// exactly 1 terminal cell wide.
let mut marker = " ".repeat(offset.saturating_sub(1));
marker.push('^');
streams.err.append(sprintf!("%s: %s\n", CMD, marker));
}
return Err(STATUS_INVALID_ARGS);
}

View File

@@ -187,7 +187,11 @@ fn print_error(&self, args: &[&wstr], streams: &mut IoStreams) {
&WString::from(e.error_message())
);
string_error!(streams, "%s: %s\n", cmd, pattern);
string_error!(streams, "%s: %*s\n", cmd, e.offset().unwrap_or(0), "^");
// TODO: This is misaligned if `pattern` contains characters which are not exactly 1
// terminal cell wide.
let mut marker = " ".repeat(e.offset().unwrap_or(0).saturating_sub(1));
marker.push('^');
string_error!(streams, "%s: %s\n", cmd, marker);
}
InvalidCaptureGroupName(name) => {
streams.err.append(wgettext_fmt!(