Example #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)
Example #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)
Example #3
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject, '[Django] %s is corrupted' % path)
     mail.outbox = []
Example #4
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject, '[Django] %s is corrupted' % path)
     mail.outbox = []
Example #5
0
 def test_format_identifier_mismatch(self):
     path = "format_identifier_mismatch"
     expected = "%(foo)s is the new %s"
     with self.activate("en-US"):
         result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject, "[Django] locale/en-US/%s.lang is corrupted" % path)
     mail.outbox = []
Example #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 = []
Example #7
0
 def test_format_identifier_mismatch(self):
     path = 'format_identifier_mismatch'
     expected = '%(foo)s is the new %s'
     with self.activate('en-US'):
         result = translate(expected, [path])
     eq_(expected, result)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].subject,
         '[Django] locale/en-US/%s.lang is corrupted' % path)
     mail.outbox = []
Example #8
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)
Example #9
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('en-US'):
         result = translate(expected, [path])
     assert_not_equal(expected, result)
     eq_(len(mail.outbox), 0)
Example #10
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, 'test_py_extract.py.txt')) 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.
        result = translate(dirty_string, ['does_not_exist'])
        eq_(result, dirty_string)

        result = translate(dirty_string, ['tweaked_message_translation'])
        eq_(result, trans_string)
Example #11
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.
        result = translate(dirty_string, ['does_not_exist'])
        eq_(result, dirty_string)

        result = translate(dirty_string, ['tweaked_message_translation'])
        eq_(result, trans_string)
Example #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("en-US"):
            result = translate(dirty_string, ["does_not_exist"])
            eq_(result, dirty_string)

            result = translate(dirty_string, ["tweaked_message_translation"])
            eq_(result, trans_string)