Merge lp:~mvo/software-center/lp941361 into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2806
Proposed branch: lp:~mvo/software-center/lp941361
Merge into: lp:software-center
Diff against target: 126 lines (+57/-20)
3 files modified
softwarecenter/ui/gtk3/review_gui_helper.py (+11/-19)
softwarecenter/utils.py (+20/-1)
test/test_utils.py (+26/-0)
To merge this branch: bzr merge lp:~mvo/software-center/lp941361
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+95920@code.launchpad.net

Description of the change

Small branch that adds a general make_string_from_list() helper to build (somewhat) i18n friendly human readable strings easily.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Thanks mvo! Nice test too! :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/ui/gtk3/review_gui_helper.py'
2--- softwarecenter/ui/gtk3/review_gui_helper.py 2012-02-04 16:34:50 +0000
3+++ softwarecenter/ui/gtk3/review_gui_helper.py 2012-03-05 15:34:23 +0000
4@@ -62,7 +62,7 @@
5 from softwarecenter.ui.gtk3.SimpleGtkbuilderApp import SimpleGtkbuilderApp
6 from softwarecenter.ui.gtk3.dialogs import SimpleGtkbuilderDialog
7 from softwarecenter.ui.gtk3.widgets.stars import ReactiveStar
8-
9+from softwarecenter.utils import make_string_from_list
10
11 from softwarecenter.backend.piston.rnrclient import RatingsAndReviewsAPI
12 from softwarecenter.backend.piston.rnrclient_pristine import ReviewRequest
13@@ -1051,27 +1051,19 @@
14 for account in failed_accounts:
15 failed_services.append("%s (@%s)" % (account['service'].capitalize(), account['username']))
16
17- failed = len(failed_services)
18-
19- #sets first part of failed services string to first account in list
20- failed_services_string = failed_services[0]
21-
22- #if more than 1 failed account in list, continues to add service strings to the failed_service_string
23- if failed > 1:
24- #comma separates services for all accounts in list up to the last one, if there is 3 or more
25- if failed > 2:
26- for i in range(1,failed-1):
27- # Translators: this is the second part of "There was a problem posting this review to %s, %s and %s"
28- failed_services_string = failed_services_string + (_(", %s") % failed_services[i])
29- #final account in list is added to end of string with 'and'
30- # Translators: this is the last part of "There was a problem posting this review to %s, %s and %s"
31- failed_services_string = failed_services_string + (_(" and %s") % failed_services[failed-1])
32-
33 glade_dialog = SimpleGtkbuilderDialog(self.datadir, domain="software-center")
34 dialog = glade_dialog.dialog_gwibber_error
35 dialog.set_transient_for(self.submit_window)
36- # Translators: this is the first part of "There was a problem posting this review to %s, %s and %s"
37- dialog.set_markup(_("There was a problem posting this review to %s.") % failed_services_string)
38+ # build the failure string
39+ # TRANSLATORS: the part in %s can either be a single entry
40+ # like "facebook" or a string like
41+ # "factbook and twister"
42+ error_str = gettext.ngettext(
43+ "There was a problem posting this review to %s.",
44+ "There was a problem posting this review to %s.",
45+ len(failed_services))
46+ error_str = make_string_from_list(error_str, failed_services)
47+ dialog.set_markup(error_str)
48 dialog.format_secondary_text(error)
49 result = dialog.run()
50 dialog.destroy()
51
52=== modified file 'softwarecenter/utils.py'
53--- softwarecenter/utils.py 2012-02-12 20:21:51 +0000
54+++ softwarecenter/utils.py 2012-03-05 15:34:23 +0000
55@@ -706,7 +706,26 @@
56 self.emit('file-download-complete', self.dest_file_path)
57
58
59-
60+def make_string_from_list(base_str, item_list):
61+ """ This function takes a list of items and builds a nice human readable
62+ string with it of the form. Note that the base string needs a "%s".
63+ Example return:
64+ The base string with the list items a,b and c in it.
65+ Note that base_str needs to be a ngettext string already, so the
66+ example usage is:
67+ l = ["foo", "bar"]
68+ base_str = ngettext("This list: %s.", "This list: %s", len(l))
69+ s = make_string_from_list(base_string, l)
70+ """
71+ list_str = item_list[0]
72+ if len(item_list) > 1:
73+ # TRANSLATORS: this is a generic list delimit char, e.g. "foo, bar"
74+ list_str = _(", ").join(item_list[:-1])
75+ # TRANSLATORS: this is the last part of a list, e.g. "foo, bar and baz"
76+ list_str = _("%s and %s") % (list_str,
77+ item_list[-1])
78+ s = base_str % list_str
79+ return s
80
81
82 # those helpers are packaging system specific
83
84=== modified file 'test/test_utils.py'
85--- test/test_utils.py 2012-03-01 11:32:37 +0000
86+++ test/test_utils.py 2012-03-05 15:34:23 +0000
87@@ -124,6 +124,31 @@
88 uuid = get_uuid()
89 self.assertTrue(uuid and len(uuid) > 0)
90
91+ def test_make_string_from_list(self):
92+ from softwarecenter.utils import make_string_from_list
93+ base = "There was a problem posting this review to %s (omg!)"
94+ # test the various forms
95+ l = ["twister"]
96+ self.assertEqual(
97+ make_string_from_list(base, l),
98+ "There was a problem posting this review to twister (omg!)")
99+ # two
100+ l = ["twister", "factbook"]
101+ self.assertEqual(
102+ make_string_from_list(base, l),
103+ "There was a problem posting this review to twister and factbook (omg!)")
104+ # three
105+ l = ["twister", "factbook", "identi.catz"]
106+ self.assertEqual(
107+ make_string_from_list(base, l),
108+ "There was a problem posting this review to twister, factbook and identi.catz (omg!)")
109+ # four
110+ l = ["twister", "factbook", "identi.catz", "baz"]
111+ self.assertEqual(
112+ make_string_from_list(base, l),
113+ "There was a problem posting this review to twister, factbook, identi.catz and baz (omg!)")
114+
115+
116 class TestExpungeCache(unittest.TestCase):
117
118 def test_expunge_cache(self):
119@@ -161,6 +186,7 @@
120 self.assertTrue(os.path.exists(os.path.join(dirname, "foo-random")))
121
122
123+
124 if __name__ == "__main__":
125 import logging
126 logging.basicConfig(level=logging.DEBUG)

Subscribers

People subscribed via source and target branches