summaryrefslogtreecommitdiffstats
path: root/tests/QtCore/translation_test.py
blob: 6b75bee363ea5054342cf0c654785b172043cb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''Unit tests to test QTranslator and translation in general.'''

import os
import unittest
from PySide.QtCore import *

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'привет мир!')

    def testUtf8(self):
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.trUtf8('Hello World!'))
        self.assertEqual(obj.objectName(), u'привет мир!')

    def testTranslateWithNoneDisambiguation(self):
        value = 'String here'
        obj = QCoreApplication.translate('context', value, None, QCoreApplication.UnicodeUTF8)
        self.assert_(isinstance(obj, unicode))
        self.assertEqual(obj, value)

if __name__ == '__main__':
    unittest.main()