Skip to content

Commit

Permalink
Fix-up of #15864: pluralize battery time reporting string (#16011)
Browse files Browse the repository at this point in the history
Fix-up of #15864.

Reported in this thread of the translators mailing list.

Summary of the issue:
When pluralizing a lot of string in #15864, the one dedicated to battery time reporting was forgotten.

Description of user facing changes
Battery time estimation will be reported with correct plural forms.

Description of development approach
Split up the string in subparts and use ngettext for hours and for minutes.
  • Loading branch information
CyrilleB79 authored Jan 7, 2024
1 parent ba19691 commit ad0fe83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
26 changes: 20 additions & 6 deletions source/winAPI/_powerTracking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2022 NV Access Limited, Rui Batista
# Copyright (C) 2022 NV Access Limited, Rui Batista, Cyrille Bougot
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

Expand Down Expand Up @@ -229,9 +229,23 @@ def _getBatteryInformation(systemPowerStatus: SystemPowerStatus) -> List[str]:
SECONDS_PER_HOUR = 3600
SECONDS_PER_MIN = 60
if systemPowerStatus.BatteryLifeTime != BATTERY_LIFE_TIME_UNKNOWN:
# Translators: This is the estimated remaining runtime of the laptop battery.
text.append(_("{hours:d} hours and {minutes:d} minutes remaining").format(
hours=systemPowerStatus.BatteryLifeTime // SECONDS_PER_HOUR,
minutes=(systemPowerStatus.BatteryLifeTime % SECONDS_PER_HOUR) // SECONDS_PER_MIN
))
nHours = systemPowerStatus.BatteryLifeTime // SECONDS_PER_HOUR
hourText = ngettext(
# Translators: This is the hour string part of the estimated remaining runtime of the laptop battery.
# E.g. if the full string is "1 hour and 34 minutes remaining", this string is "1 hour".
"{hours:d} hour",
"{hours:d} hours",
nHours,
).format(hours=nHours)
nMinutes = (systemPowerStatus.BatteryLifeTime % SECONDS_PER_HOUR) // SECONDS_PER_MIN
minuteText = ngettext(
# Translators: This is the minute string part of the estimated remaining runtime of the laptop battery.
# E.g. if the full string is "1 hour and 34 minutes remaining", this string is "34 minutes".
"{minutes:d} minute",
"{minutes:d} minutes",
nMinutes,
).format(minutes=nMinutes)
# Translators: This is the main string for the estimated remaining runtime of the laptop battery.
# E.g. hourText is replaced by "1 hour" and minuteText by "34 minutes".
text.append(_("{hourText} and {minuteText} remaining").format(hourText=hourText, minuteText=minuteText))
return text
8 changes: 4 additions & 4 deletions tests/unit/test_winAPI/test_powerTracking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2022 NV Access Limited
# Copyright (C) 2022 NV Access Limited, Cyrille Bougot
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -69,7 +69,7 @@ def test_fetch_status_full_report(self):
oldPowerState=PowerState.AC_OFFLINE,
)
self.assertEqual(
['1 percent', '1 hours and 1 minutes remaining', "Unplugged"],
['1 percent', '1 hour and 1 minute remaining', "Unplugged"],
actualSpeech,
)

Expand All @@ -96,7 +96,7 @@ def test_ac_status_change_statusChanged_connected(self):
oldPowerState=PowerState.AC_OFFLINE,
)
self.assertEqual(
["Plugged in", '1 percent', '1 hours and 1 minutes remaining'],
["Plugged in", '1 percent', '1 hour and 1 minute remaining'],
actualSpeech,
)

Expand All @@ -110,7 +110,7 @@ def test_ac_status_change_statusChanged_disconnected(self):
oldPowerState=PowerState.AC_ONLINE,
)
self.assertEqual(
["Unplugged", '1 percent', '1 hours and 1 minutes remaining'],
["Unplugged", '1 percent', '1 hour and 1 minute remaining'],
actualSpeech,
)

Expand Down

0 comments on commit ad0fe83

Please sign in to comment.