Merge lp:~evfool/update-manager/lp351665 into lp:update-manager

Proposed by Robert Roth
Status: Merged
Merged at revision: 2320
Proposed branch: lp:~evfool/update-manager/lp351665
Merge into: lp:update-manager
Diff against target: 34 lines (+7/-8)
1 file modified
UpdateManager/Core/utils.py (+7/-8)
To merge this branch: bzr merge lp:~evfool/update-manager/lp351665
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+90569@code.launchpad.net

Description of the change

Use ngettext to localize humanized size, because some languages use separate singular and plural for x kB. (LP: #351665)

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks a lot! merged now, I added a small testcase.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UpdateManager/Core/utils.py'
2--- UpdateManager/Core/utils.py 2012-01-25 16:59:26 +0000
3+++ UpdateManager/Core/utils.py 2012-01-28 06:30:29 +0000
4@@ -20,7 +20,9 @@
5 # USA
6
7 from gettext import gettext as _
8+from gettext import ngettext
9 from stat import (S_IMODE, ST_MODE, S_IXUSR)
10+from math import ceil
11
12 import apt_pkg
13 apt_pkg.init_config()
14@@ -387,15 +389,12 @@
15 """
16 Convert a given size in bytes to a nicer better readable unit
17 """
18- if bytes == 0:
19- # TRANSLATORS: download size is 0
20- return _("0 kB")
21- elif bytes < 1000:
22- # TRANSLATORS: download size of very small updates
23- return _("1 kB")
24- elif bytes < 1000 * 1000:
25+
26+ if bytes < 1000 * 1000:
27+ # to have 0 for 0 bytes, 1 for 0-1000 bytes and for 1 and above round up
28+ size_in_kb = int(ceil(bytes/float(1000)));
29 # TRANSLATORS: download size of small updates, e.g. "250 kB"
30- return locale.format_string(_("%.0f kB"), bytes/1000)
31+ return ngettext("%(size).0f kB", "%(size).0f kB", size_in_kb) % { "size" : size_in_kb }
32 else:
33 # TRANSLATORS: download size of updates, e.g. "2.3 MB"
34 return locale.format_string(_("%.1f MB"), bytes / 1000.0 / 1000.0)

Subscribers

People subscribed via source and target branches

to status/vote changes: