~smokesignals-developers/mailman/smokesignals

« back to all changes in this revision

Viewing changes to src/mailman/testing/i18n.py

  • Committer: Jens W. Klein
  • Date: 2009-12-08 13:14:48 UTC
  • mfrom: (6810.2.31 3.0)
  • Revision ID: jensens@minime-20091208131448-v09w6o3h7ln2uvoc
resync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Internationalization for the tests."""
 
19
 
 
20
from __future__ import absolute_import, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'install_testing_i18n',
 
25
    ]
 
26
 
 
27
 
 
28
from contextlib import closing
 
29
from flufl.i18n import registry
 
30
from gettext import GNUTranslations, NullTranslations
 
31
from pkg_resources import resource_stream
 
32
 
 
33
from mailman.core.i18n import initialize as core_initialize
 
34
 
 
35
 
 
36
 
 
37
class TestingStrategy:
 
38
    """A strategy that finds catalogs in the testing directory."""
 
39
 
 
40
    def __init__(self, name):
 
41
        self.name = name
 
42
 
 
43
    def __call__(self, language_code):
 
44
        if language_code == 'en':
 
45
            return NullTranslations()
 
46
        mo_file = 'mailman-%s.mo' % language_code
 
47
        with closing(resource_stream('mailman.testing', mo_file)) as fp:
 
48
            return GNUTranslations(fp)
 
49
 
 
50
 
 
51
 
 
52
def initialize():
 
53
    """Install a global underscore function for testing purposes."""
 
54
    strategy = TestingStrategy('mailman-testing')
 
55
    application = registry.register(strategy)
 
56
    core_initialize(application)