Example #1
0
    def test_attr_value(self):
        """Should not translate tags with translate as the value of an attr."""
        buf = io.StringIO(
            '<html><div id="translate">hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([], messages)
    def test_trim_translate_tag(self):
        buf = StringIO(
            "<html><translate> \n hello\n world! \n "
            "</translate></html>")

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!', [])], messages)
    def test_filter(self):
        # test also for some forms that should not match
        buf = StringIO(
            """
            <img alt="{$ 'hello world1' | translate $}">
            <p>{$'hello world2'|translate$}</p>
            <img alt="something {$'hello world3'|translate$} something
            {$'hello world4'|translate$}">
            <img alt="{$expr()|translate$}">
            <img alt="{$'some other thing'$}">
            <p>{$'"it\\'s awesome"'|translate$}</p>
            <p>{$"oh \\"hello\\" there"|translate$}</p>
            """
        )

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (2, u'gettext', 'hello world1', []),
                (3, u'gettext', 'hello world2', []),
                (4, u'gettext', 'hello world3', []),
                (4, u'gettext', 'hello world4', []),
                (8, u'gettext', '"it\\\'s awesome"', []),
                (9, u'gettext', 'oh \\"hello\\" there', []),
            ],
            messages)
    def test_filter(self):
        # test also for some forms that should not match
        buf = StringIO(
            """
            <img alt="{$ 'hello world1' | translate $}">
            <p>{$'hello world2'|translate$}</p>
            <img alt="something {$'hello world3'|translate$} something
            {$'hello world4'|translate$}">
            <img alt="{$expr()|translate$}">
            <img alt="{$'some other thing'$}">
            <p>{$'"it\\'s awesome"'|translate$}</p>
            <p>{$"oh \\"hello\\" there"|translate$}</p>
            """
        )

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (2, u'gettext', 'hello world1', []),
                (3, u'gettext', 'hello world2', []),
                (4, u'gettext', 'hello world3', []),
                (4, u'gettext', 'hello world4', []),
                (8, u'gettext', '"it\\\'s awesome"', []),
                (9, u'gettext', 'oh \\"hello\\" there', []),
            ],
            messages)
Example #5
0
    def test_interpolation_object(self):
        buf = StringIO("""<html><div translate>hello {$name.attr$}!</div>
            <translate>hello {$name.attr$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, 'gettext', 'hello %(name.attr)!', []),
                          (2, 'gettext', 'hello %(name.attr)!', [])], messages)
    def test_trim_translate_tag(self):
        buf = StringIO(
            "<html><translate> \n hello\n world! \n "
            "</translate></html>")

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello\n world!', [])], messages)
    def test_plural_form(self):
        buf = StringIO(
            ('<html><translate translate-plural="hello {$count$} worlds!">' "hello one world!</translate></html>")
        )

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, "ngettext", ("hello one world!", "hello {$count$} worlds!"), [])], messages)
    def test_simple_string(self):
        buf = StringIO("""<html><translate>hello world!</translate>'
            <div translate>hello world!</div></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, u'gettext', 'hello world!', []),
                          (2, u'gettext', 'hello world!', [])], messages)
    def test_attr_value_plus_directive(self):
        """Unless they also have a translate directive."""
        buf = StringIO(
            '<html><div id="translate" translate>hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!', [])], messages)
Example #10
0
    def test_attr_value_plus_directive(self):
        """Unless they also have a translate directive."""
        buf = io.StringIO(
            '<html><div id="translate" translate>hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!', [])], messages)
    def test_simple_string(self):
        buf = StringIO(
            """<html><translate>hello world!</translate>'
            <div translate>hello world!</div></html>"""
        )

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, u"gettext", "hello world!", []), (2, u"gettext", "hello world!", [])], messages)
Example #12
0
    def test_attr_value(self):
        """We should not translate tags that have translate as the value of an
        attribute.
        """
        buf = StringIO('<html><div id="translate">hello world!</div>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([], messages)
Example #13
0
    def test_interpolation_dict_double_quote(self):
        buf = StringIO("""<html><div translate>hello {$name["key"]$}!</div>
            <translate>hello {$name["key"]$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, 'gettext', r'hello %(name["key"])!', []),
                          (2, 'gettext', r'hello %(name["key"])!', [])],
                         messages)
Example #14
0
    def test_interpolation_func_call(self):
        buf = StringIO("""<html><div translate>hello {$func(name)$}!</div>
            '<translate>hello {$func(name)$}!</translate>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, u'gettext', 'hello %(func(name))!', []),
                          (2, u'gettext', 'hello %(func(name))!', [])],
                         messages)
    def test_nested_translate_tag(self):
        buf = StringIO("<html><translate>hello <b>beautiful <i>world</i></b> !"
                       "</translate></html>")

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [(1, 'gettext', 'hello <b>beautiful <i>world</i></b> !', [])],
            messages)
    def test_comments(self):
        buf = StringIO('<html><div translate translate-comment='
                       '"What a beautiful world">hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [(1, 'gettext', 'hello world!', ['What a beautiful world'])],
            messages)
Example #17
0
    def test_attr_value(self):
        """We should not translate tags that have translate as the value of an
        attribute.
        """
        buf = StringIO('<html><div id="translate">hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([], messages)
    def test_plural_form(self):
        buf = StringIO(
            ('<html><translate translate-plural="hello {$count$} worlds!">'
             'hello one world!</translate></html>'))

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [(1, 'ngettext',
              ('hello one world!', 'hello {$count$} worlds!'), [])], messages)
    def test_multiple_comments(self):
        buf = StringIO(
            "<html><translate "
            'translate-comment="What a beautiful world"'
            'translate-comment="Another comment"'
            ">hello world!</translate></html>"
        )

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, "gettext", "hello world!", ["What a beautiful world", "Another comment"])], messages)
Example #20
0
    def test_nested_translate_tag(self):
        buf = StringIO(
            "<html><translate>hello <b>beautiful <i>world</i></b> !"
            "</translate></html>"
        )

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [(1, 'gettext', 'hello <b>beautiful <i>world</i></b> !', [])],
            messages)
    def test_multiple_comments(self):
        buf = StringIO('<html><translate '
                       'translate-comment="What a beautiful world"'
                       'translate-comment="Another comment"'
                       '>hello world!</translate></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!',
                           ['What a beautiful world', 'Another comment'])],
                         messages)
Example #22
0
    def test_interpolation_spaces(self):
        """Spaces are not valid in interpolation expressions, but we don't
        currently complain about them
        """
        buf = StringIO("""<html><div translate>hello {$name attr$}!</div>
        <translate>hello {$name attr$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([(1, 'gettext', 'hello {$name attr$}!', []),
                          (2, 'gettext', 'hello {$name attr$}!', [])],
                         messages)
Example #23
0
    def test_comments(self):
        buf = StringIO(
            '<html><div translate translate-comment='
            '"What a beautiful world">hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [
                (1, 'gettext', 'hello world!', ['What a beautiful world'])
            ],
            messages)
Example #24
0
    def test_interpolation_object(self):
        buf = StringIO(
            """<html><div translate>hello {$name.attr$}!</div>
            <translate>hello {$name.attr$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (1, 'gettext', 'hello %(name.attr)!', []),
                (2, 'gettext', 'hello %(name.attr)!', [])
            ],
            messages)
 def test_nested_variations(self):
     buf = StringIO('''
         <p translate>To <a href="link">link</a> here</p>
         <p translate>To <!-- a comment!! --> here</p>
         <p translate>To trademark&reg; &#62; &#x3E; here</p>
         ''')
     messages = list(extract_angular(buf, [], [], {}))
     self.assertEqual([
         (2, u'gettext', 'To <a href="link">link</a> here', []),
         (3, u'gettext', 'To <!-- a comment!! --> here', []),
         (4, u'gettext', u'To trademark® &#62; &#x3E; here', []),
     ], messages)
Example #26
0
    def test_interpolation_dict_double_quote(self):
        buf = StringIO(
            """<html><div translate>hello {$name["key"]$}!</div>
            <translate>hello {$name["key"]$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (1, 'gettext', r'hello %(name["key"])!', []),
                (2, 'gettext', r'hello %(name["key"])!', [])
            ],
            messages)
Example #27
0
    def test_interpolation_func_call(self):
        buf = StringIO(
            """<html><div translate>hello {$func(name)$}!</div>
            '<translate>hello {$func(name)$}!</translate>"""
        )

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (1, u'gettext', 'hello %(func(name))!', []),
                (2, u'gettext', 'hello %(func(name))!', [])
            ],
            messages)
Example #28
0
    def test_interpolation_spaces(self):
        """Spaces are not valid in interpolation expressions, but we don't
        currently complain about them
        """
        buf = StringIO("""<html><div translate>hello {$name attr$}!</div>
        <translate>hello {$name attr$}!</translate></html>""")

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual(
            [
                (1, 'gettext', 'hello {$name attr$}!', []),
                (2, 'gettext', 'hello {$name attr$}!', [])
            ],
            messages)
 def test_nested_variations(self):
     buf = StringIO(
         '''
         <p translate>To <a href="link">link</a> here</p>
         <p translate>To <!-- a comment!! --> here</p>
         <p translate>To trademark&reg; &#62; &#x3E; here</p>
         '''
     )
     messages = list(extract_angular(buf, [], [], {}))
     self.assertEqual(
         [
             (2, u'gettext', 'To <a href="link">link</a> here', []),
             (3, u'gettext', 'To <!-- a comment!! --> here', []),
             (4, u'gettext', u'To trademark® &#62; &#x3E; here', []),
         ],
         messages)
Example #30
0
    def test_multiple_comments(self):
        buf = StringIO(
            '<html><translate '
            'translate-comment="What a beautiful world"'
            'translate-comment="Another comment"'
            '>hello world!</translate></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual(
            [
                (1, 'gettext', 'hello world!',
                 [
                     'What a beautiful world',
                     'Another comment'
                 ])
            ],
            messages)
    def test_extract_no_tags(self):
        buf = StringIO('<html></html>')

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([], messages)
Example #32
0
    def test_translate_tag(self):
        buf = StringIO('<html><translate>hello world!</translate></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!', [])], messages)
Example #33
0
    def test_translate_tag(self):
        buf = io.StringIO('<html><translate>hello world!</translate></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, 'gettext', 'hello world!', [])], messages)
Example #34
0
    def test_extract_no_tags(self):
        buf = StringIO('<html></html>')

        messages = list(extract_angular(buf, default_keys, [], {}))
        self.assertEqual([], messages)
    def test_translate_tag(self):
        buf = StringIO("<html><translate>hello world!</translate></html>")

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, "gettext", "hello world!", [])], messages)
    def test_comments(self):
        buf = StringIO("<html><div translate translate-comment=" '"What a beautiful world">hello world!</div></html>')

        messages = list(extract_angular(buf, [], [], {}))
        self.assertEqual([(1, "gettext", "hello world!", ["What a beautiful world"])], messages)