Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

app: simplify translation setup

We will be using i18n.N_() everywhere so we no longer need to monkey-
patch Qt's translate().

This is a pre-requisite for fixing #157.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
commit 0ca30933636b18d7924727a363705828c9de1fab 1 parent ece7de6
@davvid davvid authored
Showing with 0 additions and 80 deletions.
  1. +0 −21 cola/app.py
  2. +0 −59 test/test_cola_app.py
View
21 cola/app.py
@@ -119,8 +119,6 @@ class ColaApplication(object):
"""
def __init__(self, argv, locale=None, gui=True):
- """Initialize our QApplication for translation
- """
cfgactions.install()
i18n.install(locale)
qtcompat.install()
@@ -130,18 +128,11 @@ def __init__(self, argv, locale=None, gui=True):
icon_dir = resources.icon_dir()
qtcompat.add_search_path(os.path.basename(icon_dir), icon_dir)
- # monkey-patch Qt's translate() to use our translate()
if gui:
self._app = instance(tuple(argv))
self._app.setWindowIcon(qtutils.git_icon())
- self._translate_base = QtGui.QApplication.translate
- QtGui.QApplication.translate = self.translate
else:
self._app = QtCore.QCoreApplication(argv)
- self._translate_base = QtCore.QCoreApplication.translate
- QtCore.QCoreApplication.translate = self.translate
- if not hasattr(self._app, 'setStyleSheet'):
- self._app.setStyleSheet = lambda x: None
self._app.setStyleSheet("""
QMainWindow::separator {
@@ -158,18 +149,6 @@ def __init__(self, argv, locale=None, gui=True):
utils.set_binary(sys.stdout)
utils.set_binary(sys.stderr)
- def translate(self, domain, txt):
- """
- Translate strings with gettext
-
- Supports @@noun/@@verb specifiers.
-
- """
- trtxt = i18n.gettext(txt)
- if trtxt[-6:-4] == '@@': # handle @@verb / @@noun
- trtxt = trtxt[:-6]
- return trtxt
-
def activeWindow(self):
"""Wrap activeWindow()"""
return self._app.activeWindow()
View
59 test/test_cola_app.py
@@ -1,59 +0,0 @@
-# -*- encoding: utf-8 -*-
-import unittest
-from PyQt4 import QtCore
-
-import cola.app
-from cola import version
-
-
-if version.check('pyqt_qrunnable', QtCore.PYQT_VERSION_STR):
- BaseTestCase = unittest.TestCase
-else:
- BaseTestCase = object
-
-
-class ColaApplicationTestCase(BaseTestCase):
- """Test cases for the ColaApplication class"""
-
- def test_translates_noun(self):
- """Test that strings with @@noun are translated
- """
- app = cola.app.ColaApplication([], locale='ja_JP', gui=False)
- expected = (unichr(0x30b3) + unichr(0x30df) +
- unichr(0x30c3) + unichr(0x30c8))
- self.assertEqual(app.translate('??', 'Commit@@noun'), expected)
-
- def test_translates_verb(self):
- """Test that strings with @@verb are translated
- """
- app = cola.app.ColaApplication([], locale='de_DE', gui=False)
- self.assertEqual(app.translate('??', 'Commit@@verb'), 'Eintragen')
-
- def test_translates_english_noun(self):
- """Test that English strings with @@noun are properly handled
- """
- app = cola.app.ColaApplication([], locale='en_US.UTF-8', gui=False)
- self.assertEqual(app.translate('??', 'Commit@@noun'), 'Commit')
-
- def test_translates_english_verb(self):
- """Test that English strings with @@verb are properly handled
- """
- app = cola.app.ColaApplication([], locale='en_US.UTF-8', gui=False)
- self.assertEqual(app.translate('??', 'Commit@@verb'), 'Commit')
-
- def test_translates_random_english(self):
- """Test that random English strings are passed through as-is
- """
- app = cola.app.ColaApplication([], locale='en_US.UTF-8', gui=False)
- self.assertEqual(app.translate('??', 'Random'), 'Random')
-
- def test_guards_against_qstring(self):
- """Test that random English strings are passed through as-is
- """
- app = cola.app.ColaApplication([], locale='en_US.UTF-8', gui=False)
- qstr = QtCore.QString('Random')
- self.assertEqual(app.translate('??', qstr), 'Random')
-
-
-if __name__ == '__main__':
- unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.