Exemple #1
0
 def test_extract(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
     messages = list(extract(mako_tmpl, {'_': None, 'gettext': None,
                                         'ungettext': (1, 2)},
                             ['TRANSLATOR:'], {}))
     expected = \
         [(1, '_', 'Page arg 1', []),
          (1, '_', 'Page arg 2', []),
          (10, 'gettext', 'Begin', []),
          (14, '_', 'Hi there!', ['TRANSLATOR: Hi there!']),
          (19, '_', 'Hello', []),
          (22, '_', 'Welcome', []),
          (25, '_', 'Yo', []),
          (36, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
          (36, 'ungettext', ('bunny', 'bunnies', None), []),
          (41, '_', 'Goodbye', ['TRANSLATOR: Good bye']),
          (44, '_', 'Babel', []),
          (45, 'ungettext', ('hella', 'hellas', None), []),
         (62, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
         (62, 'ungettext', ('bunny', 'bunnies', None), []),
         (68, '_', 'Goodbye, really!', ['TRANSLATOR: HTML comment']),
         (71, '_', 'P.S. byebye', []),
         (77, '_', 'Top', []),
         (83, '_', 'foo', []),
         (83, '_', 'hoho', []),
          (85, '_', 'bar', []),
          (92, '_', 'Inside a p tag', ['TRANSLATOR: <p> tag is ok?']),
          (95, '_', 'Later in a p tag', ['TRANSLATOR: also this']),
          (99, '_', 'No action at a distance.', []),
          ]
     self.assertEqual(expected, messages)
Exemple #2
0
 def test_extract(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
     messages = list(
         extract(mako_tmpl, {
             '_': None,
             'gettext': None,
             'ungettext': (1, 2)
         }, ['TRANSLATOR:'], {}))
     expected = \
         [(1, '_', 'Page arg 1', []),
          (1, '_', 'Page arg 2', []),
          (10, 'gettext', 'Begin', []),
          (14, '_', 'Hi there!', ['TRANSLATOR: Hi there!']),
          (19, '_', 'Hello', []),
          (22, '_', 'Welcome', []),
          (25, '_', 'Yo', []),
          (36, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
          (36, 'ungettext', ('bunny', 'bunnies', None), []),
          (41, '_', 'Goodbye', ['TRANSLATOR: Good bye']),
          (44, '_', 'Babel', []),
          (45, 'ungettext', ('hella', 'hellas', None), []),
         (62, '_', 'The', ['TRANSLATOR: Ensure so and', 'so, thanks']),
         (62, 'ungettext', ('bunny', 'bunnies', None), []),
         (68, '_', 'Goodbye, really!', ['TRANSLATOR: HTML comment']),
         (71, '_', 'P.S. byebye', []),
         (77, '_', 'Top', []),
         (83, '_', 'foo', []),
         (83, '_', 'hoho', []),
          (85, '_', 'bar', []),
          (92, '_', 'Inside a p tag', ['TRANSLATOR: <p> tag is ok?']),
          (95, '_', 'Later in a p tag', ['TRANSLATOR: also this']),
          (99, '_', 'No action at a distance.', []),
          ]
     self.assertEqual(expected, messages)
 def test_extract_cp1251(self):
     mako_tmpl = open(os.path.join(template_base, "gettext_cp1251.mako"),
                      "rb")
     message = next(
         extract(mako_tmpl, set(["_", None]), [], {"encoding": "cp1251"}))
     # "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
     assert message == (1, "_", u"\u0442\u0435\u0441\u0442", [])
Exemple #4
0
 def test_extract_cp1251(self, extract):
     with open(os.path.join(config.template_base, "gettext_cp1251.mako"),
               "rb") as mako_tmpl:
         message = next(
             extract(mako_tmpl, {"_", None}, [], {"encoding": "cp1251"}))
         # "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
         assert message == (1, "_", "\u0442\u0435\u0441\u0442", [])
Exemple #5
0
 def test_extract(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
     messages = list(extract(mako_tmpl, {'_': None, 'gettext': None,
                                         'ungettext': (1, 2)},
                             ['TRANSLATOR:'], {}))
     expected = \
         [(1, '_', u'Page arg 1', []),
          (1, '_', u'Page arg 2', []),
          (10, 'gettext', u'Begin', []),
          (14, '_', u'Hi there!', [u'TRANSLATOR: Hi there!']),
          (19, '_', u'Hello', []),
          (22, '_', u'Welcome', []),
          (25, '_', u'Yo', []),
          (36, '_', u'The', [u'TRANSLATOR: Ensure so and', u'so, thanks']),
          (36, 'ungettext', (u'bunny', u'bunnies', None), []),
          (41, '_', u'Goodbye', [u'TRANSLATOR: Good bye']),
          (44, '_', u'Babel', []),
          (45, 'ungettext', (u'hella', u'hellas', None), []),
          (62, '_', u'Goodbye, really!', [u'TRANSLATOR: HTML comment']),
          (65, '_', u'P.S. byebye', []),
          (71, '_', u'Top', []), 
          (77, '_', u'foo', []),
          (77, '_', u'baz', []),
          (79, '_', u'bar', [])
          ]
     self.assertEqual(expected, messages)
Exemple #6
0
 def test_extract(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
     messages = list(
         extract(mako_tmpl, {
             '_': None,
             'gettext': None,
             'ungettext': (1, 2)
         }, ['TRANSLATOR:'], {}))
     expected = \
         [(1, '_', u'Page arg 1', []),
          (1, '_', u'Page arg 2', []),
          (10, 'gettext', u'Begin', []),
          (14, '_', u'Hi there!', [u'TRANSLATOR: Hi there!']),
          (19, '_', u'Hello', []),
          (22, '_', u'Welcome', []),
          (25, '_', u'Yo', []),
          (36, '_', u'The', [u'TRANSLATOR: Ensure so and', u'so, thanks']),
          (36, 'ungettext', (u'bunny', u'bunnies', None), []),
          (41, '_', u'Goodbye', [u'TRANSLATOR: Good bye']),
          (44, '_', u'Babel', []),
          (45, 'ungettext', (u'hella', u'hellas', None), []),
         (62, '_', u'The', [u'TRANSLATOR: Ensure so and', u'so, thanks']),
         (62, 'ungettext', (u'bunny', u'bunnies', None), []),
         (68, '_', u'Goodbye, really!', [u'TRANSLATOR: HTML comment']),
         (71, '_', u'P.S. byebye', []),
         (77, '_', u'Top', []),
         (83, '_', u'foo', []),
         (83, '_', u'baz', []),
         (85, '_', u'bar', [])
          ]
     self.assertEqual(expected, messages)
Exemple #7
0
 def test_extract_utf8(self):
     mako_tmpl = open(
         os.path.join(template_base, "gettext_utf8.mako"), "rb"
     )
     self.addCleanup(mako_tmpl.close)
     message = next(
         extract(mako_tmpl, set(["_", None]), [], {"encoding": "utf-8"})
     )
     assert message == (1, "_", u"K\xf6ln", [])
 def test_translator_comment(self):
     input = io.BytesIO(compat.b('''
     <p>
       ## TRANSLATORS: This is a comment.
       ${_("Message")}
     </p>'''))
     messages = list(extract(input, ['_'], ['TRANSLATORS:'], {}))
     self.assertEqual(
         messages,
         [(4, '_', compat.u('Message'),
             [compat.u('TRANSLATORS: This is a comment.')])])
Exemple #9
0
 def test_translator_comment(self, extract):
     input_ = io.BytesIO(b"""
     <p>
       ## TRANSLATORS: This is a comment.
       ${_("Message")}
     </p>""")
     messages = list(extract(input_, ["_"], ["TRANSLATORS:"], {}))
     eq_(
         messages,
         [(
             4,
             "_",
             ("Message"),
             [("TRANSLATORS: This is a comment.")],
         )],
     )
 def test_translator_comment(self):
     input_ = io.BytesIO(
         compat.b("""
     <p>
       ## TRANSLATORS: This is a comment.
       ${_("Message")}
     </p>"""))
     messages = list(extract(input_, ["_"], ["TRANSLATORS:"], {}))
     self.assertEqual(
         messages,
         [(
             4,
             "_",
             compat.u("Message"),
             [compat.u("TRANSLATORS: This is a comment.")],
         )],
     )
Exemple #11
0
 def test_extract(self):
     mako_tmpl = open(os.path.join("test_htdocs", "gettext.mako"))
     messages = list(extract(mako_tmpl, {"_": None, "gettext": None, "ungettext": (1, 2)}, ["TRANSLATOR:"], {}))
     expected = [
         (1, "_", u"Page arg 1", []),
         (1, "_", u"Page arg 2", []),
         (10, "gettext", u"Begin", []),
         (14, "_", u"Hi there!", [u"Hi there!"]),
         (19, "_", u"Hello", []),
         (22, "_", u"Welcome", []),
         (25, "_", u"Yo", []),
         (36, "_", u"The", [u"Ensure so and", u"so, thanks"]),
         (36, "ungettext", (u"bunny", u"bunnies", None), []),
         (41, "_", u"Goodbye", [u"Good bye"]),
         (44, "_", u"Babel", []),
         (45, "ungettext", (u"hella", u"hellas", None), []),
         (62, "_", u"Goodbye, really!", [u"HTML comment"]),
         (65, "_", u"P.S. byebye", []),
         (71, "_", u"Top", []),
     ]
     self.assertEqual(expected, messages)
Exemple #12
0
 def test_extract(self, extract):
     with open(os.path.join(config.template_base,
                            "gettext.mako")) as mako_tmpl:
         messages = list(
             extract(
                 mako_tmpl,
                 {
                     "_": None,
                     "gettext": None,
                     "ungettext": (1, 2)
                 },
                 ["TRANSLATOR:"],
                 {},
             ))
         expected = [
             (1, "_", "Page arg 1", []),
             (1, "_", "Page arg 2", []),
             (10, "gettext", "Begin", []),
             (14, "_", "Hi there!", ["TRANSLATOR: Hi there!"]),
             (19, "_", "Hello", []),
             (22, "_", "Welcome", []),
             (25, "_", "Yo", []),
             (36, "_", "The", ["TRANSLATOR: Ensure so and", "so, thanks"]),
             (36, "ungettext", ("bunny", "bunnies", None), []),
             (41, "_", "Goodbye", ["TRANSLATOR: Good bye"]),
             (44, "_", "Babel", []),
             (45, "ungettext", ("hella", "hellas", None), []),
             (62, "_", "The", ["TRANSLATOR: Ensure so and", "so, thanks"]),
             (62, "ungettext", ("bunny", "bunnies", None), []),
             (68, "_", "Goodbye, really!", ["TRANSLATOR: HTML comment"]),
             (71, "_", "P.S. byebye", []),
             (77, "_", "Top", []),
             (83, "_", "foo", []),
             (83, "_", "hoho", []),
             (85, "_", "bar", []),
             (92, "_", "Inside a p tag", ["TRANSLATOR: <p> tag is ok?"]),
             (95, "_", "Later in a p tag", ["TRANSLATOR: also this"]),
             (99, "_", "No action at a distance.", []),
         ]
     eq_(expected, messages)
 def test_python_gettext_call(self):
     input_ = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
     messages = list(extract(input_, ["_"], [], {}))
     self.assertEqual(messages, [(1, "_", compat.u("Message"), [])])
Exemple #14
0
 def test_extract_utf8(self, extract):
     with open(os.path.join(config.template_base, "gettext_utf8.mako"),
               "rb") as mako_tmpl:
         message = next(
             extract(mako_tmpl, {"_", None}, [], {"encoding": "utf-8"}))
         assert message == (1, "_", "K\xf6ln", [])
Exemple #15
0
 def test_python_gettext_call(self, extract):
     input_ = io.BytesIO(b'<p>${_("Message")}</p>')
     messages = list(extract(input_, ["_"], [], {}))
     eq_(messages, [(1, "_", ("Message"), [])])
Exemple #16
0
 def test_parse_python_expression(self, extract):
     input_ = io.BytesIO(b'<p>${_("Message")}</p>')
     messages = list(extract(input_, ["_"], [], {}))
     eq_(messages, [(1, "_", ("Message"), [])])
Exemple #17
0
 def test_python_gettext_call(self):
     input = io.BytesIO(compat.b('<p>${_("Message")}</p>'))
     messages = list(extract(input, ['_'], [], {}))
     self.assertEqual(messages, [(1, '_', compat.u('Message'), [])])
Exemple #18
0
 def test_extract_utf8(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext_utf8.mako'), 'rb')
     message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'utf-8'}))
     assert message == (1, '_', u'K\xf6ln', [])
Exemple #19
0
 def test_extract_cp1251(self):
     mako_tmpl = open(os.path.join(template_base, 'gettext_cp1251.mako'), 'rb')
     message = next(extract(mako_tmpl, set(['_', None]), [], {'encoding': 'cp1251'}))
     # "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
     assert message == (1, '_', u'\u0442\u0435\u0441\u0442', [])