Example #1
0
    def test_blocktrans_tag_with_variable_escaping(self):
        text = '\n<a href="http://google.com">%(name)s</a> without group\n'
        content = """
{% load fluent %}
{% blocktrans %}
<a href="http://google.com">{{ name }}</a> without group
{% endblocktrans %}
        """
        results = parse_file(content, ".html")
        expected = [
            (text, '', '', DEFAULT_TRANSLATION_GROUP),
        ]
        self.assertEqual(results, expected)

        data = {'name': "Ola & Ola"}
        rendered = Template(content).render(Context(data))
        self.assertTrue('&lt;a href=&quot;http://google.com&quot;&gt;Ola &amp; Ola&lt;/a&gt; without group' in rendered)

        # create master translation for the string and test it renders correctly
        key = MasterTranslation.generate_key(text, '', 'en-us')
        MasterTranslation.objects.create(
            pk=key, text=text, language_code='en-us'
        )
        rendered = Template(content).render(Context(data))
        self.assertTrue('&lt;a href=&quot;http://google.com&quot;&gt;Ola &amp; Ola&lt;/a&gt; without group' in rendered)
Example #2
0
    def test_blocktrans_tag_with_variable_and_group_escaping(self):
        text = '\n<a href="http://google.com">%(name)s</a> in group\n'
        content = """
{% load fluent %}
{% blocktrans group "public" %}
<a href="http://google.com">{{ name }}</a> in group
{% endblocktrans %}
        """
        results = parse_file(content, ".html")
        expected = [
            (text, '', '', 'public'),
        ]
        self.assertEqual(results, expected)

        data = {'name': "Ola & Ola"}
        rendered = Template(content).render(Context(data))
        self.assertTrue('&lt;a href=&quot;http://google.com&quot;&gt;Ola &amp; Ola&lt;/a&gt; in group' in rendered)

        # create master translation for the string and test it renders correctly
        key = MasterTranslation.generate_key(text, '', 'en-us')
        mt = MasterTranslation.objects.create(
            pk=key, text=text, language_code='en-us'
        )
        mt.used_by_groups_in_code_or_templates = {'public'}
        mt.save()

        rendered = Template(content).render(Context(data))
        self.assertTrue('&lt;a href=&quot;http://google.com&quot;&gt;Ola &amp; Ola&lt;/a&gt; in group' in rendered)
Example #3
0
    def test_blocktrans_tag_with_group(self):
        text = "\nTest trans block with group\n"
        content = """
{% load fluent %}
{% blocktrans group "public" %}
Test trans block with group
{% endblocktrans %}
        """
        results = parse_file(content, ".html")
        expected = [
            (text, '', '', 'public'),
        ]
        self.assertEqual(results, expected)
        rendered = Template(content).render(Context())
        self.assertTrue(text in rendered)

        # create master translation for the string and test it renders correctly
        key = MasterTranslation.generate_key(text, '', 'en-us')
        mt = MasterTranslation.objects.create(
            pk=key, text=text, language_code='en-us'
        )
        mt.used_by_groups_in_code_or_templates = {'public'}
        mt.save()

        rendered = Template(content).render(Context())
        self.assertTrue("Test trans block with group" in rendered)
Example #4
0
 def test_basic_html_parsing(self):
     results = parse_file(TEST_HTML_CONTENT, ".html")
     expected = [
         ('Test trans string with group', '', '', 'public'),
         ('Test trans string without group', '', '', DEFAULT_TRANSLATION_GROUP),
         ('\nTest trans block with group\n', '', '', 'public'),
         ('\nTest trans block without group\n', '', '', DEFAULT_TRANSLATION_GROUP),
     ]
     self.assertEqual(results, expected)
Example #5
0
 def test_basic_python_parsing(self):
     results = parse_file(TEST_PYTHON_CONTENT, ".py")
     expected = [
         ('Test string', '', '', DEFAULT_TRANSLATION_GROUP),
         ('Test string with hint', '', 'hint', DEFAULT_TRANSLATION_GROUP),
         ('Test string with group', '', '', 'public'),
         ('Test string with hint and group', '', 'hint', 'public'),
         ('Plural string with hint and group', 'plural', 'hint', 'public'),
     ]
     self.assertEqual(results, expected)
Example #6
0
    def test_trans_tag_without_group(self):
        text = "Test trans string without group"
        content = """
{% load fluent %}
{% trans "Test trans string without group" %}
        """
        results = parse_file(content, ".html")
        expected = [(text, '', '', DEFAULT_TRANSLATION_GROUP)]
        self.assertEqual(results, expected)

        rendered = Template(content).render(Context())
        self.assertTrue(text in rendered)

        # create master translation for the string and test it renders correctly
        key = MasterTranslation.generate_key(text, '', 'en-us')
        MasterTranslation.objects.create(
            pk=key, text=text, language_code='en-us'
        )
        rendered = Template(content).render(Context())
        self.assertTrue("Test trans string without group" in rendered)
Example #7
0
    def test_blocktrans_tag_and_noescape(self):
        text = "\nTest blocktrans & unescaping\n"
        content = """
{% load fluent %}
{% blocktrans noescape %}
Test blocktrans & unescaping
{% endblocktrans %}
        """
        results = parse_file(content, ".html")
        expected = [(text, '', '', DEFAULT_TRANSLATION_GROUP)]
        self.assertEqual(results, expected)

        rendered = Template(content).render(Context())
        self.assertTrue(text in rendered)

        # create master translation for the string and test it renders correctly
        key = MasterTranslation.generate_key(text, '', 'en-us')
        MasterTranslation.objects.create(
            pk=key, text=text, language_code='en-us'
        )
        rendered = Template(content).render(Context())
        self.assertTrue("Test blocktrans & unescaping" in rendered)