Bug#1034378: Allow Percentage Formatting in apt

2023-06-02 Thread Emir SARI
Hello,

MR created: https://salsa.debian.org/apt-team/apt/-/merge_requests/294

Best regards,
Emir (ఽ఺఍)

** E-mail needs to stay simple
** Use plain text e-mail



Bug#1034378: Allow Percentage Formatting in apt

2023-05-17 Thread Emir SARI
(Re-sending, since my previous message formatting got messed-up)

Hello,

> 16 May 2023 tarihinde 16:41 itibarıyla David Kalnischkies 
>  ş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 ortype changes from int to double etc. Feel free to correct me
though. I amnew 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 
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



Bug#1034378: Allow Percentage Formatting in apt

2023-05-17 Thread Emir SARI
Hello,I will attach a new version while I still have some time and waitingfor account approval.16 May 2023 tarihinde 16:41 itibarıyla David Kalnischkies  ş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, yourchange also uses std::printf which means it would print directly tostdout, 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 ismy other remark) and assemble the individual strings with e.g."Progress: [%s]". The code could format a "%100" first to establish themaximum 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 ortype changes from int to double etc. Feel free to correct me though. I amnew to C-like languages.Oh, and one more thing: Comments in code meant for translators are perconvention prefixed with: "TRANSLATORS: " (see existing usages) andshould try a little harder to convey what a string is used for,meanwhile a "localize according to your locale settings" could besaid about each and every string…Done.Best regards,EmirFrom 4e7e0db117990e9469295934b0c7462e8c11255f Mon Sep 17 00:00:00 2001
From: Emir SARI 
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



Bug#1034378: Allow Percentage Formatting in apt

2023-05-16 Thread Emir SARI
Hello,

> Thanks – but could you perhaps create a merge request on salsa [0]
> rather than attaching patches to bug reports as that is easier to
> review and less likely to get lost. It also runs out test and all
> such, so it gives you and reviewers some direct visible feedback.

Thanks for the reply.

I’ve tried to register on Salsa, but my accounts have not been approved yet. 
I’ve tried two times with usernames bitigchi and emirsari. Is it possible to 
direct me to a support channels about this?

I will look at the patch and try to modify as per your comments.


Best,
Emir


Bug#1034378: Allow Percentage Formatting in apt

2023-05-05 Thread Emir SARI
Hello,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.EmirFrom 091f902682c7cb7b3a4c5340df3fb0bbcd910aaa Mon Sep 17 00:00:00 2001
From: Emir SARI 
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



Bug#1034378: Allow Percentage Formatting in apt

2023-04-18 Thread Emir SARI
Hello,

> David Kalnischkies  şunları yazdı (15 Nis 2023 15:31):
> 
> Hi,
> 
>> On Thu, Apr 13, 2023 at 11:49:01PM +0300, Emir SARI wrote:
>> The percentage formatting among different locales can vary. For instance, 
>> Turkish uses %100 style formatting, whereas French uses 100 %. There are 
>> also other languages that use varying styles like using non-break spaces 
>> between the sign and the number and else. However, the percentage values 
>> displayed in apt only uses a fixed format, such as 100%.
> 
> Can you give example(s) of the messages you refer to?

Yes, Progress message is one of them, and also there are percentages on each 
individual package and/or repository update string.

> These "%.0f%%" are indeed not marked for translation, but I am not sure
> if it is a good idea as they come without any explanation and show info
> pretty densely more or less to the benefit of "something is happening"
> rather than "here are all the details you could possibly ask for so you
> can refer back to this great knowledge forever".
> 
> Never the less I suppose we can put in the work to make them
> translatable (currently the formatting is hardcoded in a few places,
> that would need to be fixed).
> On the other hand, it seems pointless labour to make the string
> translatable if a similar translatable string isn't used in this way,
> so as a compromise I suggest a deal: I will see to implement it if
> a language team/translator asks for it here.

I have contacted Mr. Dirik, as he’s the current translator and CC’d him here. 
He said he is going to fix the Progress string, your help in i18n’sing other 
currently non-i18n percentages would be really appreciated and make it more 
coherent among all apt.


Thank you for your help.
Best regards,
Emir


Bug#1034378: Allow Percentage Formatting in apt

2023-04-13 Thread Emir SARI
Package: apt

Hello,

The percentage formatting among different locales can vary. For instance, 
Turkish uses %100 style formatting, whereas French uses 100 %. There are also 
other languages that use varying styles like using non-break spaces between the 
sign and the number and else. However, the percentage values displayed in apt 
only uses a fixed format, such as 100%.

Please allow localising the percentage values. This will allow a more complete 
l10n experience, where the translated text matches the other locale formatting.