Example #1
0
 def test_unfinished_entries(self):
     testfile = os.path.join(
         os.path.dirname(__file__),
         'en-untranslated.ts'
     )
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(self.language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     lang = Language.objects.by_code_or_alias('el')
     testfile = os.path.join(
         os.path.dirname(__file__),
         'gr-untranslated.ts'
     )
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(lang)
     handler.parse_file()
     handler.save2db()
     handler.compile()
     self.assertEqual(handler.compiled_template.count('unfinished'), 2)
Example #2
0
    def test_special_characters(self):
        """Test that escaping/unescaping happens correctly"""

        unescaped_string = "& < > \" '"
        escaped_string = "&amp; &lt; &gt; &quot; &apos;"

        # Empty our resource
        SourceEntity.objects.filter(resource=self.resource).delete()

        # Make sure that we have no suggestions to begin with
        self.assertEqual(Suggestion.objects.filter(source_entity__in=
            SourceEntity.objects.filter(resource=self.resource).values('id')).count(), 0)

        # Import file with two senteces
        handler = LinguistHandler('%s/special_characters/en.ts' %
            os.path.split(__file__)[0])
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)

        # Make sure that we have all sources in the db
        self.assertEqual(SourceEntity.objects.filter(
            resource=self.resource).values('id').count(), 1)

        # Make sure that we have all translations in the db
        self.assertEqual(Translation.objects.filter(source_entity__in=
            SourceEntity.objects.filter(resource=self.resource).values('id')).count(),1)

        source = SourceEntity.objects.filter(resource=self.resource)[0]
        translation = Translation.objects.get(source_entity=source)

        self.assertEqual(source.string, unescaped_string)
        self.assertEqual(translation.string, unescaped_string)

        handler.compile()

        self.assertTrue(escaped_string in handler.compiled_template)
        self.assertFalse(unescaped_string in handler.compiled_template)
Example #3
0
 def test_context_generation(self):
     """Test creating the context of a source entity."""
     testfile = os.path.join(
         os.path.dirname(__file__),
         'comment/en.ts'
     )
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(self.language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     handler.compile()
     doc = xml.dom.minidom.parseString(handler.compiled_template)
     root = doc.documentElement
     for message in doc.getElementsByTagName("message"):
         source = _getElementByTagName(message, "source")
         sourceString = _getText(source.childNodes)
         generated_context = handler._context_of_message(message)
         # this shouldn't raise any exceptions
         se = SourceEntity.objects.get(
             resource=self.resource, string=sourceString,
             context=generated_context or u"None"
         )
Example #4
0
 def test_unfinished_entries(self):
     testfile = os.path.join(os.path.dirname(__file__),
                             'en-untranslated.ts')
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(self.language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     lang = Language.objects.by_code_or_alias('el')
     testfile = os.path.join(os.path.dirname(__file__),
                             'gr-untranslated.ts')
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(lang)
     handler.parse_file()
     handler.save2db()
     compiled_template = handler.compile()
     self.assertEqual(compiled_template.count('unfinished'), 2)
Example #5
0
    def test_special_characters(self):
        """Test that escaping/unescaping happens correctly"""

        unescaped_string = "& < > \" '"
        escaped_string = "&amp; &lt; &gt; &quot; &apos;"

        # Empty our resource
        SourceEntity.objects.filter(resource=self.resource).delete()

        # Make sure that we have no suggestions to begin with
        self.assertEqual(
            Suggestion.objects.filter(
                source_entity__in=SourceEntity.objects.filter(
                    resource=self.resource).values('id')).count(), 0)

        # Import file with two senteces
        handler = LinguistHandler('%s/special_characters/en.ts' %
                                  os.path.split(__file__)[0])
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)

        # Make sure that we have all sources in the db
        self.assertEqual(
            SourceEntity.objects.filter(
                resource=self.resource).values('id').count(), 1)

        # Make sure that we have all translations in the db
        self.assertEqual(
            Translation.objects.filter(
                source_entity__in=SourceEntity.objects.filter(
                    resource=self.resource).values('id')).count(), 1)

        source = SourceEntity.objects.filter(resource=self.resource)[0]
        translation = Translation.objects.get(source_entity=source)

        self.assertEqual(source.string, unescaped_string)
        self.assertEqual(translation.string, unescaped_string)

        compiled_template = handler.compile()

        self.assertIn(escaped_string, compiled_template)
        self.assertNotIn(unescaped_string, compiled_template)
Example #6
0
 def test_context_generation(self):
     """Test creating the context of a source entity."""
     testfile = os.path.join(os.path.dirname(__file__), 'comment/en.ts')
     handler = LinguistHandler(testfile)
     handler.bind_resource(self.resource)
     handler.set_language(self.language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     compiled_template = handler.compile()
     doc = xml.dom.minidom.parseString(compiled_template)
     root = doc.documentElement
     for message in doc.getElementsByTagName("message"):
         source = _getElementByTagName(message, "source")
         sourceString = _getText(source.childNodes)
         generated_context = _context_of_message(message)
         # this shouldn't raise any exceptions
         se = SourceEntity.objects.get(resource=self.resource,
                                       string=sourceString,
                                       context=generated_context or u"None")