Exemplo n.º 1
0
    def test_translate(self, mock_translation):
        en_message = 'A message in the default locale'
        es_translation = 'A message in Spanish'
        message = _message.Message(en_message)

        es_translations = {en_message: es_translation}
        translations_map = {'es': es_translations}
        translator = fakes.FakeTranslations.translator(translations_map)
        mock_translation.side_effect = translator

        # translate() works on msgs and on objects whose unicode reps are msgs
        obj = utils.SomeObject(message)
        self.assertEqual(es_translation, _translate.translate(message, 'es'))
        self.assertEqual(es_translation, _translate.translate(obj, 'es'))
Exemplo n.º 2
0
    def test_translate(self, mock_translation):
        en_message = "A message in the default locale"
        es_translation = "A message in Spanish"
        message = _message.Message(en_message)

        es_translations = {en_message: es_translation}
        translations_map = {"es": es_translations}
        translator = fakes.FakeTranslations.translator(translations_map)
        mock_translation.side_effect = translator

        # translate() works on msgs and on objects whose unicode reps are msgs
        obj = utils.SomeObject(message)
        self.assertEqual(es_translation, _translate.translate(message, "es"))
        self.assertEqual(es_translation, _translate.translate(obj, "es"))
Exemplo n.º 3
0
 def test_extra_lang(self):
     languages = _gettextutils.get_available_languages('oslo')
     languages.append(_FAKE_LANG)
     self.useFixture(fixture.PrefixLazyTranslation(languages=languages))
     raw_id1 = 'fake msg1'
     expected_msg_en_US = ('oslo_i18n/' +
                           fixture.PrefixLazyTranslation._DEFAULT_LANG +
                           ': ' + raw_id1)
     expected_msg_en_ZZ = 'oslo_i18n/' + _FAKE_LANG + ': ' + raw_id1
     msg1 = _(raw_id1)  # noqa
     self.assertEqual(languages,
                      _gettextutils.get_available_languages('oslo_i18n'))
     self.assertEqual(languages,
                      oslo_i18n.get_available_languages('oslo_i18n'))
     self.assertEqual(expected_msg_en_US, _translate.translate(msg1))
     self.assertEqual(expected_msg_en_ZZ,
                      _translate.translate(msg1, desired_locale=_FAKE_LANG))
Exemplo n.º 4
0
 def test_extra_lang(self):
     languages = _gettextutils.get_available_languages('oslo')
     languages.append(_FAKE_LANG)
     self.useFixture(fixture.PrefixLazyTranslation(languages=languages))
     raw_id1 = 'fake msg1'
     expected_msg_en_US = ('oslo_i18n/' +
                           fixture.PrefixLazyTranslation._DEFAULT_LANG +
                           ': ' + raw_id1)
     expected_msg_en_ZZ = 'oslo_i18n/' + _FAKE_LANG + ': ' + raw_id1
     msg1 = _(raw_id1)     # noqa
     self.assertEqual(languages,
                      _gettextutils.get_available_languages('oslo_i18n'))
     self.assertEqual(languages,
                      oslo_i18n.get_available_languages('oslo_i18n'))
     self.assertEqual(expected_msg_en_US, _translate.translate(msg1))
     self.assertEqual(expected_msg_en_ZZ,
                      _translate.translate(msg1,
                                           desired_locale=_FAKE_LANG))
Exemplo n.º 5
0
    def _translate_and_log_record(self, record):
        record.msg = _translate.translate(record.msg, self.locale)

        # In addition to translating the message, we also need to translate
        # arguments that were passed to the log method that were not part
        # of the main message e.g., log.info(_('Some message %s'), this_one))
        record.args = _translate.translate_args(record.args, self.locale)

        self.target.emit(record)
Exemplo n.º 6
0
    def _translate_and_log_record(self, record):
        record.msg = _translate.translate(record.msg, self.locale)

        # In addition to translating the message, we also need to translate
        # arguments that were passed to the log method that were not part
        # of the main message e.g., log.info(_('Some message %s'), this_one))
        record.args = _translate.translate_args(record.args, self.locale)

        self.target.emit(record)
Exemplo n.º 7
0
    def test_default(self):

        # Turn lazy off to check that fixture turns it on
        self.useFixture(fixture.ToggleLazy(False))
        self.useFixture(fixture.PrefixLazyTranslation())
        self.assertTrue(_lazy.USE_LAZY)
        default_lang = fixture.PrefixLazyTranslation._DEFAULT_LANG
        raw_id1 = 'fake msg1'
        expected_msg = 'oslo_i18n/' + default_lang + ': ' + raw_id1
        msg1 = _(raw_id1)    # noqa
        self.assertEqual([default_lang],
                         _gettextutils.get_available_languages('oslo_i18n'))
        self.assertEqual([default_lang],
                         oslo_i18n.get_available_languages('oslo_i18n'))
        self.assertEqual(expected_msg, _translate.translate(msg1))
Exemplo n.º 8
0
    def test_default(self):

        # Turn lazy off to check that fixture turns it on
        self.useFixture(fixture.ToggleLazy(False))
        self.useFixture(fixture.PrefixLazyTranslation())
        self.assertTrue(_lazy.USE_LAZY)
        default_lang = fixture.PrefixLazyTranslation._DEFAULT_LANG
        raw_id1 = 'fake msg1'
        expected_msg = 'oslo_i18n/' + default_lang + ': ' + raw_id1
        msg1 = _(raw_id1)  # noqa
        self.assertEqual([default_lang],
                         _gettextutils.get_available_languages('oslo_i18n'))
        self.assertEqual([default_lang],
                         oslo_i18n.get_available_languages('oslo_i18n'))
        self.assertEqual(expected_msg, _translate.translate(msg1))