Merge lp:~mvo/software-center/review-language-i18n into lp:software-center

Proposed by Michael Vogt on 2012-01-18
Status: Merged
Merged at revision: 2676
Proposed branch: lp:~mvo/software-center/review-language-i18n
Merge into: lp:software-center
Diff against target: 281 lines (+107/-40)
7 files modified
debian/control (+1/-0)
softwarecenter/i18n.py (+34/-5)
softwarecenter/ui/gtk3/app.py (+2/-10)
softwarecenter/ui/gtk3/widgets/reviews.py (+14/-7)
test/gtk3/test_appdetailsview.py (+4/-1)
test/test_i18n.py (+52/-0)
test/test_utils.py (+0/-17)
To merge this branch: bzr merge lp:~mvo/software-center/review-language-i18n
Reviewer Review Type Date Requested Status
Gary Lasker (community) 2012-01-18 Approve on 2012-01-18
Review via email: mp+89103@code.launchpad.net

Description of the change

This branch makes the language selection combo in the reviews widget nicer by adding a proper i18n name to it.

To post a comment you must log in.
Gary Lasker (gary-lasker) wrote :

Hi mvo, thanks for this! So, this looks very cool, but I found one problem when I tried to test using the French locals as shown (I have French langpacks installed on my system):

  LANGUAGE=fr_FR.utf8 LC_ALL=fr_FR.utf8 PYTHONPATH=. python ./software-center

The issue that I see is that there is only a single combobox entry, for "All languages" (in English), and there is no option for "French". And even given that, I see only French reviews in the list:

  http://img811.imageshack.us/img811/506/logithqueubuntu026.png

So, I'm not sure if my test case is somehow not valid/complete, but I thought I'd note it here.

One last thing, this behavior is not coming with this branch. I observe the same in trunk at rev 2675.

Nevertheless, per our conversation in IRC, you'd like to hold off on this in order to fix this one bit, so I'll set this as "Needs Fixing" for tracking.

Thanks!

review: Needs Fixing
2676. By Michael Vogt on 2012-01-18

fix bug that Gary discovered when LANGUAGE is set to a non-working language and add test

Gary Lasker (gary-lasker) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2012-01-05 11:10:58 +0000
3+++ debian/control 2012-01-18 19:55:41 +0000
4@@ -21,6 +21,7 @@
5 Architecture: all
6 Depends: ${python:Depends},
7 ${misc:Depends},
8+ iso-codes,
9 app-install-data (>= 0.4.0),
10 aptdaemon (>= 0.40),
11 software-center-aptdaemon-plugins,
12
13=== modified file 'softwarecenter/i18n.py'
14--- softwarecenter/i18n.py 2011-10-13 13:48:13 +0000
15+++ softwarecenter/i18n.py 2012-01-18 19:55:41 +0000
16@@ -16,6 +16,7 @@
17 # this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20+import locale
21 import logging
22 import os
23 LOG = logging.getLogger(__name__)
24@@ -26,14 +27,29 @@
25 # can be abbreved
26 FULL = ["pt_BR",
27 "zh_CN", "zh_TW"]
28+
29+def init_locale():
30+ try:
31+ locale.setlocale(locale.LC_ALL, "")
32+ # we need this for bug #846038, with en_NG setlocale() is fine
33+ # but the next getlocale() will crash (fun!)
34+ locale.getlocale()
35+ except:
36+ LOG.exception("setlocale failed, resetting to C")
37+ locale.setlocale(locale.LC_ALL, "C")
38+
39+
40 def get_languages():
41 """Helper that returns the split up languages"""
42- if not "LANGUAGE" in os.environ:
43+ langs = []
44+ if "LANGUAGE" in os.environ:
45+ langs = os.environ["LANGUAGE"].split(":")
46+ for lang in langs[:]:
47+ if "_" in lang and not lang in FULL:
48+ langs.remove(lang)
49+ # fallback
50+ if not langs:
51 return [get_language()]
52- langs = os.environ["LANGUAGE"].split(":")
53- for lang in langs[:]:
54- if "_" in lang and not lang in FULL:
55- langs.remove(lang)
56 return langs
57
58 def get_language():
59@@ -51,3 +67,16 @@
60 if language in FULL:
61 return language
62 return language.split("_")[0]
63+
64+def langcode_to_name(langcode):
65+ import xml.etree.ElementTree
66+ from gettext import dgettext
67+ for iso in ["iso_639_3", "iso_639"]:
68+ path = os.path.join("/usr/share/xml/iso-codes/", iso+".xml")
69+ if os.path.exists(path):
70+ root = xml.etree.ElementTree.parse(path)
71+ xpath = ".//iso_639_3_entry[@part1_code='%s']" % langcode
72+ match = root.find(xpath)
73+ if match is not None:
74+ return dgettext(iso, match.attrib["name"])
75+ return langcode
76
77=== modified file 'softwarecenter/ui/gtk3/app.py'
78--- softwarecenter/ui/gtk3/app.py 2012-01-17 15:56:14 +0000
79+++ softwarecenter/ui/gtk3/app.py 2012-01-18 19:55:41 +0000
80@@ -22,7 +22,6 @@
81
82 import atexit
83 import collections
84-import locale
85 import dbus
86 import dbus.service
87 from dbus.mainloop.glib import DBusGMainLoop
88@@ -48,6 +47,7 @@
89 # db imports
90 from softwarecenter.db.application import Application
91 from softwarecenter.db import DebFileApplication
92+from softwarecenter.i18n import init_locale
93
94 # misc imports
95 from softwarecenter.plugin import PluginManager
96@@ -187,15 +187,7 @@
97 gettext.bindtextdomain("software-center", "/usr/share/locale")
98 gettext.textdomain("software-center")
99
100- try:
101- locale.setlocale(locale.LC_ALL, "")
102- # we need this for bug #846038, with en_NG setlocale() is fine
103- # but the next getlocale() will crash (fun!)
104- locale.getlocale()
105- except:
106- LOG.exception("setlocale failed, resetting to C")
107- locale.setlocale(locale.LC_ALL, "C")
108-
109+ init_locale()
110
111 if "SOFTWARE_CENTER_DEBUG_TABS" in os.environ:
112 self.notebook_view.set_show_tabs(True)
113
114=== modified file 'softwarecenter/ui/gtk3/widgets/reviews.py'
115--- softwarecenter/ui/gtk3/widgets/reviews.py 2012-01-17 20:43:04 +0000
116+++ softwarecenter/ui/gtk3/widgets/reviews.py 2012-01-18 19:55:41 +0000
117@@ -39,7 +39,7 @@
118 )
119
120
121-from softwarecenter.i18n import get_languages
122+from softwarecenter.i18n import get_languages, langcode_to_name
123
124 from softwarecenter.netstatus import network_state_is_connected, get_network_watcher
125 from softwarecenter.enums import (
126@@ -55,6 +55,9 @@
127 LOG_ALLOCATION = logging.getLogger("softwarecenter.ui.Gtk.get_allocation()")
128 LOG = logging.getLogger(__name__)
129
130+(COL_LANGNAME,
131+ COL_LANGCODE) = range(2)
132+
133 class UIReviewsList(Gtk.VBox):
134
135 __gsignals__ = {
136@@ -127,10 +130,15 @@
137 self.header.pack_end(self.sort_combo, False, False, 3)
138
139 # change language
140- self.review_language = Gtk.ComboBoxText.new()
141+ self.review_language = Gtk.ComboBox()
142+ cell = Gtk.CellRendererText()
143+ self.review_language.pack_start(cell, True)
144+ self.review_language.add_attribute(cell, "text", COL_LANGNAME)
145+ self.review_language_model = Gtk.ListStore(str, str)
146 for lang in get_languages():
147- self.review_language.append_text(lang)
148- self.review_language.append_text(_('Any language'))
149+ self.review_language_model.append( (langcode_to_name(lang), lang) )
150+ self.review_language_model.append( (_('Any language'), 'any') )
151+ self.review_language.set_model(self.review_language_model)
152 self.review_language.set_active(0)
153 self.review_language.connect(
154 "changed", self._on_different_review_language_clicked)
155@@ -307,9 +315,8 @@
156 self.emit("different-review-language-clicked", language)
157
158 def get_active_review_language(self):
159- language = self.review_language.get_active_text()
160- if language == _('Any language'):
161- language = 'any'
162+ model = self.review_language.get_model()
163+ language = model[self.review_language.get_active_iter()][COL_LANGCODE]
164 return language
165
166 def get_all_review_ids(self):
167
168=== modified file 'test/gtk3/test_appdetailsview.py'
169--- test/gtk3/test_appdetailsview.py 2012-01-17 21:25:58 +0000
170+++ test/gtk3/test_appdetailsview.py 2012-01-18 19:55:41 +0000
171@@ -108,6 +108,10 @@
172 view.show_app(app)
173 self.assertEqual(view._reviews_server_page, 1)
174
175+ def test_human_readable_name_in_view(self):
176+ model = self.view.reviews.review_language.get_model()
177+ self.assertEqual(model[0][0], "English")
178+
179 def test_pkgstatus_bar(self):
180 # make sure configure is run with the various states
181 # test
182@@ -155,7 +159,6 @@
183 "for state %s the function %s was not called" % (state, func))
184 mock.reset()
185
186-
187 def test_switch_language_resets_page(self):
188 self.view._reviews_server_page = 4
189
190
191=== added file 'test/test_i18n.py'
192--- test/test_i18n.py 1970-01-01 00:00:00 +0000
193+++ test/test_i18n.py 2012-01-18 19:55:41 +0000
194@@ -0,0 +1,52 @@
195+#!/usr/bin/python
196+
197+import os
198+import unittest
199+
200+
201+from testutils import setup_test_env
202+setup_test_env()
203+from softwarecenter.i18n import (
204+ init_locale, get_language, get_languages, langcode_to_name)
205+
206+class TestI18n(unittest.TestCase):
207+ """ tests the sc i18n """
208+
209+ def test_langcode_to_name(self):
210+ self.assertEqual(langcode_to_name("de"), "German")
211+
212+ def test_locale(self):
213+ # needs lang + country code
214+ os.environ["LANGUAGE"] = "zh_TW"
215+ self.assertEqual(get_language(), "zh_TW")
216+ # language only
217+ os.environ["LANGUAGE"] = "fr_FR"
218+ self.assertEqual(get_language(), "fr")
219+ # not existing one
220+ os.environ["LANGUAGE"] = "xx_XX"
221+ self.assertEqual(get_language(), "en")
222+ # LC_ALL, no language
223+ del os.environ["LANGUAGE"]
224+ os.environ["LC_ALL"] = "C"
225+ os.environ["LANG"] = "C"
226+ self.assertEqual(get_language(), "en")
227+
228+ def test_invalid_get_languages(self):
229+ # set LANGUAGE to a invalid language and verify that it correctly
230+ # falls back to english
231+ os.environ["LANGUAGE"] = "yxy_YYY"
232+ self.assertEqual(get_languages(), ["en"])
233+
234+ def test_init_locale(self):
235+ import locale
236+ os.environ["LANGUAGE"] = ""
237+ os.environ["LANG"] = "en_US.UTF-8"
238+ init_locale()
239+ self.assertEqual(locale.getlocale(locale.LC_ALL), ("en_US", "UTF-8"))
240+
241+
242+
243+if __name__ == "__main__":
244+ import logging
245+ logging.basicConfig(level=logging.DEBUG)
246+ unittest.main()
247
248=== modified file 'test/test_utils.py'
249--- test/test_utils.py 2012-01-16 14:42:49 +0000
250+++ test/test_utils.py 2012-01-18 19:55:41 +0000
251@@ -10,7 +10,6 @@
252 release_filename_in_lists_from_deb_line,
253 get_http_proxy_string_from_libproxy,
254 )
255-from softwarecenter.i18n import get_language
256
257
258 class TestSCUtils(unittest.TestCase):
259@@ -28,22 +27,6 @@
260 self.assertEqual(release_filename_in_lists_from_deb_line(debline),
261 "security.ubuntu.com_ubuntu_dists_maverick-security_Release")
262
263- def test_locale(self):
264- # needs lang + country code
265- os.environ["LANGUAGE"] = "zh_TW"
266- self.assertEqual(get_language(), "zh_TW")
267- # language only
268- os.environ["LANGUAGE"] = "fr_FR"
269- self.assertEqual(get_language(), "fr")
270- # not existing one
271- os.environ["LANGUAGE"] = "xx_XX"
272- self.assertEqual(get_language(), "en")
273- # LC_ALL, no language
274- del os.environ["LANGUAGE"]
275- os.environ["LC_ALL"] = "C"
276- os.environ["LANG"] = "C"
277- self.assertEqual(get_language(), "en")
278-
279 def test_get_http_proxy_from_gsettings(self):
280 from softwarecenter.utils import get_http_proxy_string_from_gsettings
281 # FIXME: do something more meaningful here once I figured out

Subscribers

People subscribed via source and target branches