Bug#1034378: Allow Percentage Formatting in apt
Hello,
I will attach a new version while I still have some time and waiting
for account approval.
16 May 2023 tarihinde 16:41 itibarıyla David Kalnischkies <david@kalnischkies.de> şunu yazdı:
The first hunk seems wrong as our 'strprintf' 'prints to a std::string'
given as first argument and doesn't return anything. Meantime, your
change also uses std::printf which means it would print directly to
stdout, which this code shouldn't do either.
Oops, silly mistake. Should be fine with the new patch.
In general, I suppose the formatting currently is "Progress: [ 42%]" so
"Progress: [ %42]" is your target?
Yes, correct.
I think we could go with a "%d%%" string for all (four) cases (which is
my other remark) and assemble the individual strings with e.g.
"Progress: [%s]". The code could format a "%100" first to establish the
maximum length and prepend spaces as needed for the real value.
I left the other three as-is for now, since it would probably require casts or
type changes from int to double etc. Feel free to correct me though. I am
new to C-like languages.
Oh, and one more thing: Comments in code meant for translators are per
convention prefixed with: "TRANSLATORS: " (see existing usages) and
should try a little harder to convey what a string is used for,
meanwhile a "localize according to your locale settings" could be
said about each and every string…
Done.
Best regards,
Emir
From 4e7e0db117990e9469295934b0c7462e8c11255f Mon Sep 17 00:00:00 2001
From: Emir SARI <emir_sari@icloud.com>
Date: Fri, 5 May 2023 18:58:03 +0300
Subject: [PATCH] Apply i18n to percentage display
Languages like Turkish and French (and some other more), use a
custom percentage format, other than the standard 100%. Allowing
i18n to these values, make the apt interface a lot coherent with
the rest of the output, since they mostly appear next to translated
strings.
This commit also fixes the issue of "Progress: [100%]" to have
extra blank characters when the percentage sign is prepended to the
number; e.g. "Progress: [ %1]". Previously, it output [% 1] due
to the absolute placeholder format.
---
apt-pkg/install-progress.cc | 12 +++++++++++-
apt-private/acqprogress.cc | 9 ++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index c7f7573..8378200 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -56,7 +56,17 @@ bool PackageManager::StatusChanged(std::string /*PackageName*/,
{
int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1);
percentage = StepsDone/(double)TotalSteps * 100.0;
- strprintf(progress_str, _("Progress: [%3li%%]"), std::lround(percentage));
+
+ std::string percent_str;
+ // TRANSLATORS: Percentage value; %d is the number, %% is the sign
+ strprintf(percent_str, _("%d%%"), std::lround(percentage));
+
+ if (percentage < 10)
+ percent_str.insert(0, " ");
+ else if (percentage < 100)
+ percent_str.insert(0, " ");
+
+ strprintf(progress_str, _("Progress: [%s]"), percent_str.c_str());
if(percentage < (last_reported_progress + reporting_steps))
return false;
diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc
index fa7edfc..f54d732 100644
--- a/apt-private/acqprogress.cc
+++ b/apt-private/acqprogress.cc
@@ -232,9 +232,11 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
if (I->CurrentItem->TotalSize > 0 && I->CurrentItem->Owner->Complete == false)
{
if (Mode == Short)
- ioprintf(S, " %.0f%%", (I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize);
+ // TRANSLATORS: Percentage value; %0.f is the number, %% is the sign
+ ioprintf(S, _(" %.0f%%"), (I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize);
else
- ioprintf(S, "/%sB %.0f%%", SizeToStr(I->CurrentItem->TotalSize).c_str(),
+ // TRANSLATORS: Percentage value; %0.f is the number, %% is the sign
+ ioprintf(S, _("/%sB %.0f%%"), SizeToStr(I->CurrentItem->TotalSize).c_str(),
(I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize);
}
S << "]";
@@ -249,7 +251,8 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
// Put in the percent done
{
std::stringstream S;
- ioprintf(S, "%.0f%%", Percent);
+ // TRANSLATORS: Percentage value; %0.f is the number, %% is the sign
+ ioprintf(S, _("%.0f%%"), Percent);
S << Line;
Line = S.str();
S.clear();
--
2.34.1
Reply to: