• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python catalog.Catalog类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中babel.messages.catalog.Catalog的典型用法代码示例。如果您正苦于以下问题:Python Catalog类的具体用法?Python Catalog怎么用?Python Catalog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Catalog类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_no_wrap_and_width_behaviour_on_comments

    def test_no_wrap_and_width_behaviour_on_comments(self):
        catalog = Catalog()
        catalog.add("Pretty dam long message id, which must really be big "
                    "to test this wrap behaviour, if not it won't work.",
                    locations=[("fake.py", n) for n in range(1, 30)])
        buf = BytesIO()
        pofile.write_po(buf, catalog, width=None, omit_header=True)
        self.assertEqual(b"""\
#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7
#: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14
#: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21
#: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
#: fake.py:29
msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
msgstr ""

""", buf.getvalue().lower())
        buf = BytesIO()
        pofile.write_po(buf, catalog, width=100, omit_header=True)
        self.assertEqual(b"""\
#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 fake.py:8 fake.py:9 fake.py:10
#: fake.py:11 fake.py:12 fake.py:13 fake.py:14 fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19
#: fake.py:20 fake.py:21 fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
#: fake.py:29
msgid ""
"pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
" work."
msgstr ""

""", buf.getvalue().lower())
开发者ID:Changaco,项目名称:babel,代码行数:30,代码来源:test_pofile.py


示例2: handle

    def handle(self, *args, **options):
        if args:
            # mimics puente.management.commands.extract for a list of files
            outputdir = os.path.join(settings.ROOT, 'locale', 'templates',
                                     'LC_MESSAGES')
            if not os.path.isdir(outputdir):
                os.makedirs(outputdir)

            catalog = Catalog(
                header_comment='',
                project=get_setting('PROJECT'),
                version=get_setting('VERSION'),
                msgid_bugs_address=get_setting('MSGID_BUGS_ADDRESS'),
                charset='utf-8',
            )

            for filename, lineno, msg, cmts, ctxt in extract_from_files(args):
                catalog.add(msg, None, [(filename, lineno)], auto_comments=cmts,
                            context=ctxt)

            with open(os.path.join(outputdir, '%s.pot' % DOMAIN), 'wb') as fp:
                write_po(fp, catalog, width=80)
        else:
            # This is basically a wrapper around the puente extract
            # command, we might want to do some things around this in the
            # future
            gettext_extract()
        pot_to_langfiles(DOMAIN)
开发者ID:Delphine,项目名称:bedrock,代码行数:28,代码来源:l10n_extract.py


示例3: run

    def run(self):
        mappings = self._get_mappings()
        with open(self.output_file, 'wb') as outfile:
            catalog = Catalog(project=self.project,
                              version=self.version,
                              msgid_bugs_address=self.msgid_bugs_address,
                              copyright_holder=self.copyright_holder,
                              charset=self.charset)

            for path, method_map, options_map in mappings:
                def callback(filename, method, options):
                    if method == 'ignore':
                        return

                    # If we explicitly provide a full filepath, just use that.
                    # Otherwise, path will be the directory path and filename
                    # is the relative path from that dir to the file.
                    # So we can join those to get the full filepath.
                    if os.path.isfile(path):
                        filepath = path
                    else:
                        filepath = os.path.normpath(os.path.join(path, filename))

                    optstr = ''
                    if options:
                        optstr = ' (%s)' % ', '.join(['%s="%s"' % (k, v) for
                                                      k, v in options.items()])
                    self.log.info('extracting messages from %s%s', filepath, optstr)

                if os.path.isfile(path):
                    current_dir = os.getcwd()
                    extracted = check_and_call_extract_file(
                        path, method_map, options_map,
                        callback, self.keywords, self.add_comments,
                        self.strip_comments, current_dir
                    )
                else:
                    extracted = extract_from_dir(
                        path, method_map, options_map,
                        keywords=self.keywords,
                        comment_tags=self.add_comments,
                        callback=callback,
                        strip_comment_tags=self.strip_comments
                    )
                for fname, lineno, msg, comments, context, flags in extracted:
                    if os.path.isfile(path):
                        filepath = fname  # already normalized
                    else:
                        filepath = os.path.normpath(os.path.join(path, fname))

                    catalog.add(msg, None, [(filepath, lineno)], flags=flags,
                                auto_comments=comments, context=context)

            self.log.info('writing PO template file to %s', self.output_file)
            write_po(outfile, catalog, width=self.width,
                     no_location=self.no_location,
                     omit_header=self.omit_header,
                     sort_output=self.sort_output,
                     sort_by_file=self.sort_by_file,
                     include_lineno=self.include_lineno)
开发者ID:JonathanRRogers,项目名称:babel,代码行数:60,代码来源:frontend.py


示例4: test_write_incomplete_plural

def test_write_incomplete_plural():
    """Test behaviour with incompletely translated plurals in .po."""
    catalog = Catalog()
    catalog.language = Language('bs') # Bosnian
    catalog.add(('foo', 'foos'), ('one', '', 'many', ''), context='foo')
    assert po2xml(catalog) == {'foo': {
        'few': '', 'many': 'many', 'other': '', 'one': 'one'}}
开发者ID:JMQCode,项目名称:android2po,代码行数:7,代码来源:test_plurals.py


示例5: _build

    def _build(self, locale, messages, path, pathGlobal=None):
        '''
        Builds a catalog based on the provided locale paths, the path is used as the main source any messages that are not
        found in path locale but are part of messages will attempt to be extracted from the global path locale.

        @param locale: Locale
            The locale.
        @param messages: Iterable(Message)
            The messages to build the PO file on.
        @param path: string
            The path of the targeted PO file from the locale repository.
        @param pathGlobal: string|None
            The path of the global PO file from the locale repository.
        @return: file like object
            File like object that contains the PO file content
        '''
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale
        assert isinstance(messages, Iterable), 'Invalid messages %s' % messages
        assert isinstance(path, str), 'Invalid path %s' % path
        assert pathGlobal is None or isinstance(pathGlobal, str), 'Invalid global path %s' % pathGlobal
        if isfile(path):
            with open(path) as fObj: catalog = read_po(fObj, locale)
        else:
            catalog = Catalog(locale, creation_date=datetime.now(), **self.catalog_config)
        if pathGlobal and isfile(pathGlobal):
            with open(pathGlobal) as fObj: catalogGlobal = read_po(fObj, locale)
        else:
            catalogGlobal = None

        self._processCatalog(catalog, messages, fallBack=catalogGlobal)
        catalog.revision_date = datetime.now()

        return catalog
开发者ID:AtomLaw,项目名称:Ally-Py,代码行数:33,代码来源:po_file_manager.py


示例6: test_po_with_multiline_obsolete_message

    def test_po_with_multiline_obsolete_message(self):
        catalog = Catalog()
        catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
        msgid = r"""Here's a message that covers
multiple lines, and should still be handled
correctly.
"""
        msgstr = r"""Here's a message that covers
multiple lines, and should still be handled
correctly.
"""
        catalog.obsolete[msgid] = Message(msgid, msgstr,
                                          locations=[('utils.py', 3)])
        buf = BytesIO()
        pofile.write_po(buf, catalog, omit_header=True)
        self.assertEqual(b'''#: main.py:1
msgid "foo"
msgstr "Voh"

#~ msgid ""
#~ "Here's a message that covers\\n"
#~ "multiple lines, and should still be handled\\n"
#~ "correctly.\\n"
#~ msgstr ""
#~ "Here's a message that covers\\n"
#~ "multiple lines, and should still be handled\\n"
#~ "correctly.\\n"''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:27,代码来源:test_pofile.py


示例7: test_write

def test_write():
    """Test writing a basic catalog.
    """
    catalog = Catalog()
    catalog.add('green', context='colors:0')
    catalog.add('red', context='colors:1')
    assert po2xml(catalog) == {'colors': ['green', 'red']}
开发者ID:Acidburn0zzz,项目名称:android2po,代码行数:7,代码来源:test_string_arrays.py


示例8: test_write_po_file_with_specified_charset

 def test_write_po_file_with_specified_charset(self):
     catalog = Catalog(charset='iso-8859-1')
     catalog.add('foo', u'äöü', locations=[('main.py', 1)])
     buf = BytesIO()
     pofile.write_po(buf, catalog, omit_header=False)
     po_file = buf.getvalue().strip()
     assert b'"Content-Type: text/plain; charset=iso-8859-1\\n"' in po_file
     assert u'msgstr "äöü"'.encode('iso-8859-1') in po_file
开发者ID:Changaco,项目名称:babel,代码行数:8,代码来源:test_pofile.py


示例9: test_write_missing_translations

def test_write_missing_translations():
    """[Regression] Specifically test that arrays are not written to the
    XML in an incomplete fashion if parts of the array are not translated.
    """
    catalog = Catalog()
    catalog.add('green', context='colors:0')    # does not have a translation
    catalog.add('red', 'rot', context='colors:1')
    assert po2xml(catalog) == {'colors': ['green', 'rot']}
开发者ID:Acidburn0zzz,项目名称:android2po,代码行数:8,代码来源:test_string_arrays.py


示例10: test_file_sorted_po

 def test_file_sorted_po(self):
     catalog = Catalog()
     catalog.add(u'bar', locations=[('utils.py', 3)])
     catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), locations=[('main.py', 1)])
     buf = BytesIO()
     pofile.write_po(buf, catalog, sort_by_file=True)
     value = buf.getvalue().strip()
     assert value.find(b'main.py') < value.find(b'utils.py')
开发者ID:Changaco,项目名称:babel,代码行数:8,代码来源:test_pofile.py


示例11: test_write

def test_write():
    """Test writing a basic catalog.
    """
    catalog = Catalog()
    catalog.add('green', context='colors:0')
    catalog.add('red', context='colors:1')
    assert etree.tostring(po2xml(catalog, with_untranslated=True)) == \
        '<resources><string-array name="colors"><item>green</item><item>red</item></string-array></resources>'
开发者ID:r3gis3r,项目名称:android2po,代码行数:8,代码来源:test_string_arrays.py


示例12: test_write_po_file_with_specified_charset

 def test_write_po_file_with_specified_charset(self):
     catalog = Catalog(charset="iso-8859-1")
     catalog.add("foo", "\xe4\xf6\xfc", locations=[("main.py", 1)])
     buf = BytesIO()
     pofile.write_po(buf, catalog, omit_header=False)
     po_file = buf.getvalue().strip()
     assert br'"Content-Type: text/plain; charset=iso-8859-1\n"' in po_file
     assert 'msgstr "\xe4\xf6\xfc"'.encode("iso-8859-1") in po_file
开发者ID:vsajip,项目名称:babel3,代码行数:8,代码来源:pofile.py


示例13: test_join_locations

    def test_join_locations(self):
        catalog = Catalog()
        catalog.add(u'foo', locations=[('main.py', 1)])
        catalog.add(u'foo', locations=[('utils.py', 3)])
        buf = BytesIO()
        pofile.write_po(buf, catalog, omit_header=True)
        self.assertEqual(b'''#: main.py:1 utils.py:3
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py


示例14: test_duplicate_comments

    def test_duplicate_comments(self):
        catalog = Catalog()
        catalog.add(u'foo', auto_comments=['A comment'])
        catalog.add(u'foo', auto_comments=['A comment'])
        buf = BytesIO()
        pofile.write_po(buf, catalog, omit_header=True)
        self.assertEqual(b'''#. A comment
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py


示例15: test_no_include_lineno

    def test_no_include_lineno(self):
        catalog = Catalog()
        catalog.add(u'foo', locations=[('main.py', 1)])
        catalog.add(u'foo', locations=[('utils.py', 3)])
        buf = BytesIO()
        pofile.write_po(buf, catalog, omit_header=True, include_lineno=False)
        self.assertEqual(b'''#: main.py utils.py
msgid "foo"
msgstr ""''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:9,代码来源:test_pofile.py


示例16: test_write

def test_write():
    """Test writing a basic catalog.
    """
    catalog = Catalog()
    catalog.add("green", context="colors:0")
    catalog.add("red", context="colors:1")
    assert (
        etree.tostring(po2xml(catalog, with_untranslated=True))
        == '<resources><string-array name="colors"><item>green</item><item>red</item></string-array></resources>'
    )
开发者ID:jakerr,项目名称:android2po,代码行数:10,代码来源:test_string_arrays.py


示例17: test_write

def test_write():
    """Test a basic po2xml() call.

    (what the import command does).
    """
    catalog = Catalog()
    catalog.language = Language('bs') # Bosnian
    catalog.add(('foo', 'foos'), ('few', 'many', 'one', 'other'), context='foo')
    assert po2xml(catalog) == {'foo': {
        'few': 'few', 'many': 'many', 'one': 'one', 'other': 'other'}}
开发者ID:dasony,项目名称:android2po,代码行数:10,代码来源:test_plurals.py


示例18: test_po_with_previous_msgid

    def test_po_with_previous_msgid(self):
        catalog = Catalog()
        catalog.add(u'foo', u'Voh', locations=[('main.py', 1)],
                    previous_id=u'fo')
        buf = BytesIO()
        pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
        self.assertEqual(b'''#: main.py:1
#| msgid "fo"
msgid "foo"
msgstr "Voh"''', buf.getvalue().strip())
开发者ID:Changaco,项目名称:babel,代码行数:10,代码来源:test_pofile.py


示例19: test_write_skipped_ids

def test_write_skipped_ids():
    """Test that arrays were ids are missing are written properly out as well.
    """
    # TODO: Indices missing at the end of the array will not be noticed,
    # because we are not aware of the arrays full length.
    # TODO: If we where smart enough to look in the original resource XML,
    # we could fill in missing array strings with the untranslated value.
    catalog = Catalog()
    catalog.add('red', context='colors:3')
    catalog.add('green', context='colors:1')
    assert po2xml(catalog) == {'colors': [None, 'green', None, 'red']}
开发者ID:Acidburn0zzz,项目名称:android2po,代码行数:11,代码来源:test_string_arrays.py


示例20: _update_piglatin

def _update_piglatin():
    from babel.messages.pofile import read_po, write_po
    from babel.messages.catalog import Catalog
    with open('app/messages.pot', 'r') as f:
        template = read_po(f)
    catalog = Catalog()
    for message in template:
        trans = ' '.join([_piglatin_translate(w) for w in message.id.split(' ')])
        catalog.add(message.id, trans, locations=message.locations)
    with open('app/translations/aa/LC_MESSAGES/messages.po', 'w') as f:
        write_po(f, catalog)
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:11,代码来源:fabfile.py



注:本文中的babel.messages.catalog.Catalog类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python extract.extract函数代码示例发布时间:2022-05-24
下一篇:
Python messages.Catalog类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap