Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 482034 | Differences between
and this patch

Collapse All | Expand All

(-)/branches/1.0-stable/trac/util/tests/__init__.py (-1 / +3 lines)
Lines 22-26 Link Here
22
22
23
from trac import util
23
from trac import util
24
from trac.util.tests import concurrency, datefmt, presentation, text, html
24
from trac.util.tests import concurrency, datefmt, presentation, text, \
25
                            translation, html
25
26
26
27
Lines 182-185 Link Here
182
    suite.addTest(doctest.DocTestSuite(util))
183
    suite.addTest(doctest.DocTestSuite(util))
183
    suite.addTest(text.suite())
184
    suite.addTest(text.suite())
185
    suite.addTest(translation.suite())
184
    suite.addTest(html.suite())
186
    suite.addTest(html.suite())
185
    return suite
187
    return suite
(-)/branches/1.0-stable/trac/util/tests/translation.py (+83 lines)
Line 0 Link Here
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright (C) 2013 Edgewall Software
4
# All rights reserved.
5
#
6
# This software is licensed as described in the file COPYING, which
7
# you should have received as part of this distribution. The terms
8
# are also available at http://trac.edgewall.org/wiki/TracLicense.
9
#
10
# This software consists of voluntary contributions made by many
11
# individuals. For the exact contribution history, see the revision
12
# history and logs, available at http://trac.edgewall.org/log/.
13
14
import shutil
15
import tempfile
16
import unittest
17
from pkg_resources import resource_exists, resource_filename
18
try:
19
    import babel
20
except ImportError:
21
    babel = None
22
    locale_identifiers = lambda: ()
23
else:
24
    try:
25
        from babel.localedata import locale_identifiers
26
    except ImportError:
27
        from babel.localedata import list as locale_identifiers
28
29
from trac.test import EnvironmentStub
30
from trac.util import translation
31
32
33
class TranslationsProxyTestCase(unittest.TestCase):
34
35
    def setUp(self):
36
        self.env = EnvironmentStub()
37
        self.env.path = tempfile.mkdtemp(prefix='trac-tempenv-')
38
39
    def tearDown(self):
40
        translation.deactivate()
41
        self.env.reset_db()
42
        shutil.rmtree(self.env.path)
43
44
    def _get_locale_dir(self):
45
        return resource_filename('trac', 'locale')
46
47
    def _get_available_locales(self):
48
        return sorted(locale
49
                      for locale in translation.get_available_locales()
50
                      if resource_exists('trac',
51
                                         'locale/%s/LC_MESSAGES/messages.mo'
52
                                         % locale))
53
54
    def test_activate(self):
55
        locales = self._get_available_locales()
56
        if locales:
57
            translation.activate(locales[0], self.env.path)
58
59
    def test_activate_unavailable_locale(self):
60
        unavailables = sorted(set(locale_identifiers()) -
61
                              set(translation.get_available_locales())) or \
62
                       ('en_US',)
63
        locale_dir = self._get_locale_dir()
64
        translation.add_domain('catalog1', self.env.path, locale_dir)
65
        translation.add_domain('catalog2', self.env.path, locale_dir)
66
        translation.activate(unavailables[0], self.env.path)
67
68
    def test_activate_with_non_existent_catalogs(self):
69
        locales = self._get_available_locales()
70
        if locales:
71
            locale_dir = self._get_locale_dir()
72
            translation.add_domain('catalog1', self.env.path, locale_dir)
73
            translation.add_domain('catalog2', self.env.path, locale_dir)
74
            translation.activate(locales[0], self.env.path)
75
76
77
def suite():
78
    suite = unittest.TestSuite()
79
    suite.addTest(unittest.makeSuite(TranslationsProxyTestCase, 'test'))
80
    return suite
81
82
if __name__ == '__main__':
83
    unittest.main(defaultTest='suite')
(-)/branches/1.0-stable/trac/util/translation.py (-3 / +10 lines)
Lines 150-155 Link Here
150
                t = self._null_translations
150
                t = self._null_translations
151
            else:
151
            else:
152
                t.add(Translations.load(locale_dir, locale or 'en_US',
152
                self._add(t, Translations.load(locale_dir, locale or 'en_US',
153
                                        'tracini'))
153
                                               'tracini'))
154
                if env_path:
154
                if env_path:
155
                    with self._plugin_domains_lock:
155
                    with self._plugin_domains_lock:
Lines 157-161 Link Here
157
                        domains = domains.items()
157
                        domains = domains.items()
158
                    for domain, dirname in domains:
158
                    for domain, dirname in domains:
159
                        t.add(Translations.load(dirname, locale, domain))
159
                        self._add(t, Translations.load(dirname, locale,
160
                                                       domain))
160
            self._current.translations = t
161
            self._current.translations = t
161
            self._activate_failed = False
162
            self._activate_failed = False
Lines 184-187 Link Here
184
            return self._current.translations is not None \
185
            return self._current.translations is not None \
185
                   or self._activate_failed
186
                   or self._activate_failed
187
188
        # Internal methods
189
190
        def _add(self, t, translations):
191
            if isinstance(translations, Translations):
192
                t.add(translations)
186
193
187
        # Delegated methods
194
        # Delegated methods

Return to bug 482034