示例#1
0
 def test_translate_skips_for_default_locale(self, cache_mock):
     """
     Translation calls should not hit the cache for the default language.
     There will never be any lang files, and the strings in the calls are
     the correct ones already.
     """
     with self.activate('fr'):
         translate('The Dude abides.', ['main'])
     self.assertEqual(cache_mock.get.call_count, 1)
     cache_mock.reset_mock()
     with self.activate(settings.LANGUAGE_CODE):
         translate('The Dude abides.', ['main'])
     self.assertEqual(cache_mock.get.call_count, 0)
示例#2
0
 def test_translate_skips_for_default_locale(self, cache_mock):
     """
     Translation calls should not hit the cache for the default language.
     There will never be any lang files, and the strings in the calls are
     the correct ones already.
     """
     with self.activate('fr'):
         translate('The Dude abides.', ['main'])
     self.assertEqual(cache_mock.get.call_count, 1)
     cache_mock.reset_mock()
     with self.activate(settings.LANGUAGE_CODE):
         translate('The Dude abides.', ['main'])
     self.assertEqual(cache_mock.get.call_count, 0)
示例#3
0
def gettext(ctx, text):
    """
    A no-op for backwards compatability.

    Once we remove all uses of `_(...)` in templates this can be removed.
    """
    return translate(text)
示例#4
0
 def test_format_identifier_mismatch(self):
     path = "format_identifier_mismatch"
     expected = "%(foo)s is the new %s"
     with self.activate("fr"):
         result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject, "[Django] locale/fr/%s.lang is corrupted" % path)
     mail.outbox = []
示例#5
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('fr'):
         result = translate(expected, [path])
     assert expected == result
     assert len(mail.outbox) == 1
     assert mail.outbox[
         0].subject == f'[bedrock] {LOCALES_PATH}/fr/{path}.lang is corrupted'
     mail.outbox = []
示例#6
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('fr'):
         result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject,
         '[Django] locale/fr/%s.lang is corrupted' % path)
     mail.outbox = []
示例#7
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('fr'):
         result = translate(expected, [path])
     assert expected == result
     assert len(mail.outbox) == 1
     assert (mail.outbox[0].subject ==
             '[bedrock] locale/fr/%s.lang is corrupted' % path)
     mail.outbox = []
示例#8
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('fr'):
         result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject,
         '[Django] locale/fr/%s.lang is corrupted' % path)
     mail.outbox = []
示例#9
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('fr'):
         result = translate(expected, [path])
     assert expected == result
     assert len(mail.outbox) == 1
     assert (
         mail.outbox[0].subject ==
         '[bedrock] locale/fr/%s.lang is corrupted' % path)
     mail.outbox = []
示例#10
0
 def test_format_identifier_order(self):
     """
     Test that the order in which the format identifier appears doesn't
     matter
     """
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %(bar)s'
     with self.activate('fr'):
         result = translate(expected, [path])
     assert_not_equal(expected, result)
     eq_(len(mail.outbox), 0)
示例#11
0
 def test_format_identifier_order(self):
     """
     Test that the order in which the format identifier appears doesn't
     matter
     """
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %(bar)s'
     with self.activate('fr'):
         result = translate(expected, [path])
     assert_not_equal(expected, result)
     eq_(len(mail.outbox), 0)
示例#12
0
    def test_extract_message_tweaks_do_not_break(self):
        """
        Extraction and translation matching should tweak msgids the same.
        """
        clean_string = u'Stuff about many things.'
        dirty_string = u'Stuff\xa0about\r\nmany\t   things.'
        trans_string = u'This is the translation.'

        # extraction
        with open(os.path.join(ROOT, 'extract_me.py')) as pyfile:
            vals = extract_tower_python(pyfile, ['_'], [], {}).next()
        eq_(vals[2], clean_string)

        # translation
        # path won't exist for en-US as there isn't a dir for that
        # in locale.
        with self.activate('fr'):
            result = translate(dirty_string, ['does_not_exist'])
            eq_(result, dirty_string)

            result = translate(dirty_string, ['tweaked_message_translation'])
            eq_(result, trans_string)
示例#13
0
    def test_extract_message_tweaks_do_not_break(self):
        """
        Extraction and translation matching should tweak msgids the same.
        """
        clean_string = u'Stuff about many things.'
        dirty_string = u'Stuff\xa0about\r\nmany\t   things.'
        trans_string = u'This is the translation.'

        # extraction
        with open(os.path.join(ROOT, 'extract_me.py')) as pyfile:
            vals = extract_tower_python(pyfile, ['_'], [], {}).next()
        eq_(vals[2], clean_string)

        # translation
        # path won't exist for en-US as there isn't a dir for that
        # in locale.
        with self.activate('fr'):
            result = translate(dirty_string, ['does_not_exist'])
            eq_(result, dirty_string)

            result = translate(dirty_string, ['tweaked_message_translation'])
            eq_(result, trans_string)
示例#14
0
    def test_extract_message_tweaks_do_not_break(self):
        """
        Extraction and translation matching should tweak msgids the same.
        """
        clean_string = u'Stuff about many things.'
        dirty_string = u'Stuff\xa0about\r\nmany\t   things.'
        trans_string = u'This is the translation.'

        # extraction
        pypath = ROOT_PATH.joinpath('extract_me.py')
        with open(str(pypath)) as pyfile:
            vals = extract_python(pyfile, ['_'], [], {}).next()
        assert vals[2] == clean_string

        # translation
        # path won't exist for en-US as there isn't a dir for that
        # in locale.
        with self.activate('fr'):
            result = translate(dirty_string, ['does_not_exist'])
            assert result == dirty_string

            result = translate(dirty_string, ['tweaked_message_translation'])
            assert result == trans_string
示例#15
0
    def test_extract_message_tweaks_do_not_break(self):
        """
        Extraction and translation matching should tweak msgids the same.
        """
        clean_string = u'Stuff about many things.'
        dirty_string = u'Stuff\xa0about\r\nmany\t   things.'
        trans_string = u'This is the translation.'

        # extraction
        pypath = ROOT_PATH.joinpath('extract_me.py')
        with io.open(str(pypath), 'rb') as pyfile:
            vals = next(extract_python(pyfile, ['_'], [], {}))
        assert vals[2] == clean_string

        # translation
        # path won't exist for en-US as there isn't a dir for that
        # in locale.
        with self.activate('fr'):
            result = translate(dirty_string, ['does_not_exist'])
            assert result == dirty_string

            result = translate(dirty_string, ['tweaked_message_translation'])
            assert result == trans_string
示例#16
0
def gettext(ctx, text):
    """Translate a string, loading the translations for the locale if
    necessary."""
    install_lang_files(ctx)
    return translate(text, ctx['request'].langfiles)
示例#17
0
def gettext(ctx, text):
    """Translate a string, loading the translations for the locale if
    necessary."""
    install_lang_files(ctx)
    return translate(text, ctx['request'].langfiles)