示例#1
0
 def _babel_extract(fp, locales, path):
     try:
         all_parts = extract.extract('jinja2.ext.babel_extract',
                                     fp,
                                     options=options,
                                     comment_tags=comment_tags)
         for parts in all_parts:
             lineno, msgid, comments, context = parts
             message = babel_catalog.Message(msgid,
                                             None,
                                             auto_comments=comments,
                                             locations=[(path, lineno)])
             _add_to_catalog(message, locales)
     except tokenize.TokenError:
         self.pod.logger.error(
             'Problem extracting body: {}'.format(path))
         raise
示例#2
0
 def _handle_field(path, locales, msgid, key, node):
     if (not key or not isinstance(key, basestring)
             or not key.endswith('@')):
         return
     # Support gettext "extracted comments" on tagged fields:
     #   field@: Message.
     #   field@#: Extracted comment for field@.
     auto_comments = []
     if isinstance(node, dict):
         auto_comment = node.get('{}#'.format(key))
         if auto_comment:
             auto_comments.append(auto_comment)
     message = catalog.Message(msgid,
                               None,
                               auto_comments=auto_comments,
                               locations=[(path, 0)])
     if msgid:
         _add_to_catalog(message, locales)
示例#3
0
 def test_tick_untranslated(self):
     stats = translation_stats.TranslationStats()
     stats.tick(catalog.Message(
         'About',
         None,
     ), 'ga', 'en')
     self.assertEqual(
         {
             'messages': {
                 'ga': {
                     'About': 1,
                 },
             },
             'untranslated': {
                 'ga': {
                     'About': 1,
                 },
             },
         }, stats.export())
示例#4
0
文件: catalog.py 项目: vsajip/babel3
    def test_mime_headers_contain_same_information_as_attributes(self):
        cat = catalog.Catalog()
        cat[''] = catalog.Message('',
                      "Last-Translator: Foo Bar <*****@*****.**>\n" +
                      "Language-Team: de <*****@*****.**>\n" +
                      "POT-Creation-Date: 2009-03-01 11:20+0200\n" +
                      "PO-Revision-Date: 2009-03-09 15:47-0700\n")
        self.assertEqual(None, cat.locale)
        mime_headers = dict(cat.mime_headers)

        self.assertEqual('Foo Bar <*****@*****.**>', cat.last_translator)
        self.assertEqual('Foo Bar <*****@*****.**>',
                         mime_headers['Last-Translator'])

        self.assertEqual('de <*****@*****.**>', cat.language_team)
        self.assertEqual('de <*****@*****.**>', mime_headers['Language-Team'])

        dt = datetime.datetime(2009, 3, 9, 15, 47, tzinfo=FixedOffsetTimezone(-7 * 60))
        self.assertEqual(dt, cat.revision_date)
        formatted_dt = format_datetime(dt, 'yyyy-MM-dd HH:mmZ', locale='en')
        self.assertEqual(formatted_dt, mime_headers['PO-Revision-Date'])
示例#5
0
    def test_export_untranslated_tracebacks(self):
        """Untranslated strings tracebacks."""
        stats = translation_stats.TranslationStats()
        stats.datetime = mock.Mock()
        stats.datetime.now.return_value = '2017-12-25 00:00:01.000000'

        expected = textwrap.dedent("""
        ================================================================================
        ===                           Untranslated Strings                           ===
        ================================================================================
        ===                 0 occurrences of 0 untranslated strings                  ===
        ===                        2017-12-25 00:00:01.000000                        ===
        ================================================================================

        ===                      No untranslated strings found.                      ===
        """)
        self.assertIn(expected.strip(), stats.export_untranslated_tracebacks())

        stats.tick(catalog.Message(
            'About',
            None,
        ), 'ga', 'en')
        stats.add_untagged({
            '/content/pages/test.yaml': 'About',
        })
        expected = textwrap.dedent("""
        ================================================================================
        ===                           Untranslated Strings                           ===
        ================================================================================
        ===                 1 occurrences of 1 untranslated strings                  ===
        ===                        2017-12-25 00:00:01.000000                        ===
        ================================================================================

        ga :: About
        """)
        self.assertIn(expected.strip(), stats.export_untranslated_tracebacks())
示例#6
0
    def test_pretty_print(self):
        lines, logger = self._mock_log()
        try:
            stats = translation_stats.TranslationStats()
            # Stub out the logging.
            stats.log = logger
            stats.tick(catalog.Message(
                'About',
                None,
            ), 'ga', 'en')
            stats.add_untagged({
                '/content/pages/test.yaml': 'About',
            })
            stats.pretty_print()
            expected = textwrap.dedent("""
            ==============================================
            ga       1   About
            """)
            expected = 'Locale   #   Untagged and Untranslated Message ' + expected
            self.assertIn(expected.strip(), lines.getvalue())

            expected = textwrap.dedent("""
            =================================
            ga       1   About
            """)
            expected = 'Locale   #   Untranslated Message ' + expected
            self.assertIn(expected.strip(), lines.getvalue())

            expected = textwrap.dedent("""
            =====================
            ga                  1
            """)
            expected = 'Locale   Untranslated ' + expected
            self.assertIn(expected.strip(), lines.getvalue())
        finally:
            lines.close()
示例#7
0
def test_message_python_format():
    assert catalog.Message('foo %(name)s bar').python_format
    assert catalog.Message(('foo %(name)s', 'foo %(name)s')).python_format
示例#8
0
def test_message_pluralizable():
    assert not catalog.Message('foo').pluralizable
    assert catalog.Message(('foo', 'bar')).pluralizable
示例#9
0
def test_message_fuzzy():
    assert not catalog.Message('foo').fuzzy
    msg = catalog.Message('foo', 'foo', flags=['fuzzy'])
    assert msg.fuzzy
    assert msg.id == 'foo'