aboutsummaryrefslogtreecommitdiffstats
path: root/tests/qtcore/translation_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qtcore/translation_test.py')
-rw-r--r--tests/qtcore/translation_test.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/qtcore/translation_test.py b/tests/qtcore/translation_test.py
new file mode 100644
index 000000000..31bb20e74
--- /dev/null
+++ b/tests/qtcore/translation_test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+'''Unit tests to test QTranslator and translation in general.'''
+
+import os
+import unittest
+from PySide.QtCore import QObject, QTranslator, QCoreApplication
+
+from helper import UsesQCoreApplication
+
+class TranslationTest(UsesQCoreApplication):
+ '''Test case for Qt translation facilities.'''
+
+ def setUp(self):
+ super(TranslationTest, self).setUp()
+ self.trdir = os.path.join(os.path.dirname(__file__), 'translations')
+ # os.system is probably not the best way to do it
+ os.system('lrelease %s/*.ts > /dev/null' % self.trdir)
+
+ def tearDown(self):
+ os.system('rm %s/*.qm > /dev/null' % self.trdir)
+ super(TranslationTest, self).tearDown()
+
+ def testLatin(self):
+ #Set string value to Latin
+ translator = QTranslator()
+ translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
+ self.app.installTranslator(translator)
+
+ obj = QObject()
+ obj.setObjectName(obj.tr('Hello World!'))
+ self.assertEqual(obj.objectName(), u'Orbis, te saluto!')
+
+ def testRussian(self):
+ #Set string value to Russian
+ translator = QTranslator()
+ translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
+ self.app.installTranslator(translator)
+
+ obj = QObject()
+ obj.setObjectName(obj.tr('Hello World!'))
+ self.assertEqual(obj.objectName(), u'привет мир!')
+
+
+if __name__ == '__main__':
+ unittest.main()
+