Merge lp:~ralsina/ubuntuone-control-panel/translate-all-the-dialogs into lp:ubuntuone-control-panel

Proposed by Roberto Alsina
Status: Merged
Approved by: Natalia Bidart
Approved revision: 284
Merged at revision: 281
Proposed branch: lp:~ralsina/ubuntuone-control-panel/translate-all-the-dialogs
Merge into: lp:ubuntuone-control-panel
Diff against target: 91 lines (+36/-0)
2 files modified
ubuntuone/controlpanel/gui/qt/main/__init__.py (+8/-0)
ubuntuone/controlpanel/gui/qt/main/tests/test_main.py (+28/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/translate-all-the-dialogs
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Diego Sarmentero (community) Approve
Review via email: mp+96889@code.launchpad.net

Commit message

- Enabled Qt translation engine so standard dialogs are translated (LP: #951651).

Description of the change

- Enabled Qt translation engine so standard dialogs are translated (Fixes lp:951651).

To test it, run like this:

python setup.py clean build && U1_DEBUG=True LANG=es_ES.UTF-8 ./bin/ubuntuone-control-panel-qt

Make sure you have language-pack-es and language-pack-gnome-es installed, then click on "Add a new folder".

You should see somthing like this: https://bugs.launchpad.net/ubuntuone-control-panel/+bug/951651/+attachment/2846209/+files/12.png

To post a comment you must log in.
284. By Roberto Alsina

test case

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

Good one!
+1

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/main/__init__.py'
2--- ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-03-08 16:40:50 +0000
3+++ ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-03-10 18:41:18 +0000
4@@ -65,6 +65,14 @@
5
6 args = ['ubuntuone-installer'] + args[1:]
7 app = UniqueApplication(args, "ubuntuone-control-panel")
8+
9+ # Install translator for standard dialogs.
10+ locale = unicode(QtCore.QLocale.system().name())
11+ translator = QtCore.QTranslator()
12+ translator.load("qt_" + locale,
13+ QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath))
14+ app.installTranslator(translator)
15+
16 parser = parser_options()
17 # Use only the arguments that are not recognized by Qt
18 args = parser.parse_args(args=[unicode(x) for x in app.arguments()[1:]])
19
20=== modified file 'ubuntuone/controlpanel/gui/qt/main/tests/test_main.py'
21--- ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-03-08 16:40:50 +0000
22+++ ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-03-10 18:41:18 +0000
23@@ -16,12 +16,24 @@
24
25 """Tests for the control panel's Qt main."""
26
27+from PyQt4 import QtCore
28 from twisted.internet.defer import inlineCallbacks
29
30 from ubuntuone.controlpanel.gui.qt import main
31 from ubuntuone.controlpanel.tests import TestCase
32
33
34+class FakeTranslator(object):
35+
36+ """A fake QTranslator."""
37+
38+ args = None
39+
40+ def load(self, *args, **kwargs):
41+ """fake load."""
42+ self.args = (args, kwargs)
43+
44+
45 class FakeApplication(object):
46
47 """A fake application."""
48@@ -29,6 +41,7 @@
49 def __init__(self):
50 self.args = None
51 self.style = None
52+ self.translator = None
53
54 def __call__(self, argv, *args, **kwargs):
55 """Fake arg filtering function."""
56@@ -41,6 +54,10 @@
57 def setStyleSheet(self, *args, **kwargs):
58 """Fake setStyleSheet."""
59 self.style = (args, kwargs)
60+
61+ def installTranslator(self, translator):
62+ """Fake installTranslator."""
63+ self.translator = translator
64 # pylint: enable=C0103
65
66 def arguments(self):
67@@ -90,9 +107,11 @@
68 def setUp(self):
69 yield super(MainTestCase, self).setUp()
70 self.app = FakeApplication()
71+ self.translator = FakeTranslator()
72 self.start = FakeStart()
73 self.patch(main, "UniqueApplication", self.app)
74 self.patch(main, "start", self.start)
75+ self.patch(QtCore, "QTranslator", lambda: self.translator)
76
77 def test_wm_class(self):
78 """Test that we set the 1st argument, used for WM_CLASS, correctly."""
79@@ -126,3 +145,12 @@
80 """Ensure the --switch-to option is parsed and passed correctly."""
81 main.main(["foobar", "--switch-to", "folders"])
82 self.assertEqual(self.start.window.tabname, "folders")
83+
84+ def test_translator(self):
85+ """Ensure the Qt translator is loaded."""
86+ main.main(["foo"])
87+ locale = unicode(QtCore.QLocale.system().name())
88+ self.assertEqual(self.app.translator, self.translator)
89+ self.assertEqual(self.translator.args, (("qt_" + locale,
90+ QtCore.QLibraryInfo.location(
91+ QtCore.QLibraryInfo.TranslationsPath)), {}))

Subscribers

People subscribed via source and target branches