Bug#1034378: Allow Percentage Formatting in apt
I'm attaching a patch that enables translations, and fixes an issue that creates extra spaces when the percentage sign is prepended to the "Progress: [100%]" string, due to the fixed layout.
Awaiting reviews.
Thanks in advance.
Emir
From 091f902682c7cb7b3a4c5340df3fb0bbcd910aaa 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 | 10 +++++++++-
apt-private/acqprogress.cc | 9 ++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index c7f7573..e7c5e55 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -56,7 +56,15 @@ 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));
+ // Progress percentage, localize according to your locale settings
+ progress_str = strprintf(_("Progress: [%d%%]"), std::lround(percentage));
+
+ if (percentage < 10)
+ progress_str.insert(11, " ");
+ else if (percentage < 100) {
+ progress_str.insert(11, " ");
+
+ std::printf("%s", progress_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..bbb15ae 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);
+ // Progress percentage, localize according to your locale settings
+ ioprintf(S, _(" %.0f%%"), (I->CurrentItem->CurrentSize*100.0)/I->CurrentItem->TotalSize);
else
- ioprintf(S, "/%sB %.0f%%", SizeToStr(I->CurrentItem->TotalSize).c_str(),
+ // Progress percentage, localize according to your locale settings
+ 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);
+ // Progress percentage, localize according to your locale settings
+ ioprintf(S, _("%.0f%%"), Percent);
S << Line;
Line = S.str();
S.clear();
--
2.34.1
Reply to: