def setUp(self):
     super(GettextTest, self).setUp()
     moxfixture = self.useFixture(moxstubout.MoxStubout())
     self.stubs = moxfixture.stubs
     self.mox = moxfixture.mox
     # remember so we can reset to it later in case it changes
     self._USE_LAZY = _lazy.USE_LAZY
     self.t = _factory.TranslatorFactory('oslo_i18n.test')
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     self.assertNotIsInstance(r, _message.Message)
Beispiel #3
0
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     # Python 2.6 doesn't have assertNotIsInstance().
     self.assertFalse(isinstance(r, _message.Message))
Beispiel #4
0
 def test_py3(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', True):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ugettext.side_effect = AssertionError(
                 'should have called gettext')
             tf = _factory.TranslatorFactory('domain')
             tf.primary('some text')
             trans.gettext.assert_called_with('some text')
 def test_plural_form_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ngettext.side_effect = AssertionError(
                 'should have called ungettext')
             tf = _factory.TranslatorFactory('domain')
             tf.plural_form('single', 'plural', 1)
             trans.ungettext.assert_called_with('single', 'plural', 1)
 def test_contextual_form_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.gettext.side_effect = AssertionError(
                 'should have called ugettext')
             trans.ugettext.return_value = "some text"
             tf = _factory.TranslatorFactory('domain')
             tf.contextual_form('context', 'some text')
             trans.ugettext.assert_called_with(
                 "%s%s%s" % ('context', CONTEXT_SEPARATOR, 'some text'))
Beispiel #7
0
def install(domain):
    """Install a _() function using the given translation domain.

    Given a translation domain, install a _() function using gettext's
    install() function.

    The main difference from gettext.install() is that we allow
    overriding the default localedir (e.g. /usr/share/locale) using
    a translation-domain-specific environment variable (e.g.
    NOVA_LOCALEDIR).

    :param domain: the translation domain
    """
    from six import moves
    tf = _factory.TranslatorFactory(domain)
    moves.builtins.__dict__['_'] = tf.primary
 def setUp(self):
     super(GettextTest, self).setUp()
     # remember so we can reset to it later in case it changes
     self._USE_LAZY = _lazy.USE_LAZY
     self.t = _factory.TranslatorFactory('oslo_i18n.test')
Beispiel #9
0
from oslo_i18n import _factory

DOMAIN = 'hypernet_agentless'

# Create the global translation functions.
_translators = _factory.TranslatorFactory(DOMAIN)

# The primary translation function using the well-known name "_"
_ = _translators.primary

_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
Beispiel #10
0
 def test_log_level_domain_name(self):
     with mock.patch.object(_factory.TranslatorFactory,
                            '_make_translation_func') as mtf:
         tf = _factory.TranslatorFactory('domain')
         tf._make_log_translation_func('mylevel')
         mtf.assert_called_with('domain-log-mylevel')
Beispiel #11
0
 def test_not_lazy(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(_message, 'Message') as msg:
         msg.side_effect = AssertionError('should not use Message')
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')
Beispiel #12
0
 def test_lazy(self):
     _lazy.enable_lazy(True)
     with mock.patch.object(_message, 'Message') as msg:
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')
         msg.assert_called_with('some text', domain='domain')
Beispiel #13
0
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""Translation support for messages in this library.
"""
import oslo_i18n
from oslo_i18n import _factory

# Create the global translation functions.
_translators = _factory.TranslatorFactory(domain='myapp')

# The primary translation function using the well-known name "_"
_ = _translators.primaryb
_C = _translators.contextual_form
_P = _translators.plural_form
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LI = _translators.log_critical
Beispiel #14
0
 def _test(self, level):
     with mock.patch.object(_factory.TranslatorFactory,
                            '_make_translation_func') as mtf:
         tf = _factory.TranslatorFactory('domain')
         getattr(tf, 'log_%s' % level)
         mtf.assert_called_with('domain-log-%s' % level)
Beispiel #15
0
# Copyright 2012 Red Hat, Inc.
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""Translation support for messages in this library.
"""

from oslo_i18n import _factory

# Create the global translation functions.
_translators = _factory.TranslatorFactory('oslo.i18n')

# The primary translation function using the well-known name "_"
_ = _translators.primary