当前位置: 首页>>代码示例>>Python>>正文


Python utils.normalize_language_tag方法代码示例

本文整理汇总了Python中docutils.utils.normalize_language_tag方法的典型用法代码示例。如果您正苦于以下问题:Python utils.normalize_language_tag方法的具体用法?Python utils.normalize_language_tag怎么用?Python utils.normalize_language_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.utils的用法示例。


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

示例1: get_language

# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import normalize_language_tag [as 别名]
def get_language(language_code, reporter=None):
    """Return module with language localizations.

    `language_code` is a "BCP 47" language tag.
    If there is no matching module, warn and fall back to English.
    """
    # TODO: use a dummy module returning emtpy strings?, configurable?
    for tag in normalize_language_tag(language_code):
        tag = tag.replace('-','_') # '-' not valid in module names
        if tag in _languages:
            return _languages[tag]
        try:
            module = __import__(tag, globals(), locals(), level=1)
        except ImportError:
            try:
                module = __import__(tag, globals(), locals(), level=0)
            except ImportError:
                continue
        _languages[tag] = module
        return module
    if reporter is not None:
        reporter.warning(
            'language "%s" not supported: ' % language_code +
            'Docutils-generated text will be in English.')
    module = __import__('en', globals(), locals(), level=1)
    _languages[tag] = module # warn only one time!
    return module 
开发者ID:skarlekar,项目名称:faces,代码行数:29,代码来源:__init__.py

示例2: get_language

# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import normalize_language_tag [as 别名]
def get_language(language_code):
    for tag in normalize_language_tag(language_code):
        tag = tag.replace('-','_') # '-' not valid in module names
        if tag in _languages:
            return _languages[tag]
        try:
            module = __import__(tag, globals(), locals(), level=1)
        except ImportError:
            try:
                module = __import__(tag, globals(), locals(), level=0)
            except ImportError:
                continue
        _languages[tag] = module
        return module
    return None 
开发者ID:skarlekar,项目名称:faces,代码行数:17,代码来源:__init__.py

示例3: language_name

# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import normalize_language_tag [as 别名]
def language_name(self, language_code):
        """Return TeX language name for `language_code`"""
        for tag in utils.normalize_language_tag(language_code):
            try:
                return self.language_codes[tag]
            except KeyError:
                pass
        if self.reporter is not None:
            self.reporter.warning(self.warn_msg % language_code)
        return '' 
开发者ID:skarlekar,项目名称:faces,代码行数:12,代码来源:__init__.py

示例4: apply

# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import normalize_language_tag [as 别名]
def apply(self):
        smart_quotes = self.document.settings.smart_quotes
        if not smart_quotes:
            return
        try:
            alternative = smart_quotes.startswith('alt')
        except AttributeError:
            alternative = False
        # print repr(alternative)

        document_language = self.document.settings.language_code

        # "Educate" quotes in normal text. Handle each block of text
        # (TextElement node) as a unit to keep context around inline nodes:
        for node in self.document.traverse(nodes.TextElement):
            # skip preformatted text blocks and special elements:
            if isinstance(node, (nodes.FixedTextElement, nodes.Special)):
                continue
            # nested TextElements are not "block-level" elements:
            if isinstance(node.parent, nodes.TextElement):
                continue

            # list of text nodes in the "text block":
            txtnodes = [txtnode for txtnode in node.traverse(nodes.Text)
                        if not isinstance(txtnode.parent,
                                          nodes.option_string)]

            # language: use typographical quotes for language "lang"
            lang = node.get_language_code(document_language)
            # use alternative form if `smart-quotes` setting starts with "alt":
            if alternative:
                if '-x-altquot' in lang:
                    lang = lang.replace('-x-altquot', '')
                else:
                    lang += '-x-altquot'
            # drop subtags missing in quotes:
            for tag in utils.normalize_language_tag(lang):
                if tag in smartquotes.smartchars.quotes:
                    lang = tag
                    break
            else: # language not supported: (keep ASCII quotes)
                if lang not in self.unsupported_languages:
                    self.document.reporter.warning('No smart quotes '
                        'defined for language "%s".'%lang, base_node=node)
                self.unsupported_languages.add(lang)
                lang = ''

            # Iterator educating quotes in plain text:
            # '2': set all, using old school en- and em- dash shortcuts
            teacher = smartquotes.educate_tokens(self.get_tokens(txtnodes),
                                                 attr='2', language=lang)

            for txtnode, newtext in zip(txtnodes, teacher):
                txtnode.parent.replace(txtnode, nodes.Text(newtext))

            self.unsupported_languages = set() # reset 
开发者ID:skarlekar,项目名称:faces,代码行数:58,代码来源:universal.py

示例5: apply

# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import normalize_language_tag [as 别名]
def apply(self):
        smart_quotes = self.document.settings.smart_quotes
        if not smart_quotes:
            return
        try:
            alternative = smart_quotes.startswith('alt')
        except AttributeError:
            alternative = False
        # print repr(alternative)

        document_language = self.document.settings.language_code
        lc_smartquotes = self.document.settings.smartquotes_locales
        if lc_smartquotes:
            smartquotes.smartchars.quotes.update(dict(lc_smartquotes))

        # "Educate" quotes in normal text. Handle each block of text
        # (TextElement node) as a unit to keep context around inline nodes:
        for node in self.document.traverse(nodes.TextElement):
            # skip preformatted text blocks and special elements:
            if isinstance(node, self.nodes_to_skip):
                continue
            # nested TextElements are not "block-level" elements:
            if isinstance(node.parent, nodes.TextElement):
                continue

            # list of text nodes in the "text block":
            txtnodes = [txtnode for txtnode in node.traverse(nodes.Text)
                        if not isinstance(txtnode.parent,
                                          nodes.option_string)]

            # language: use typographical quotes for language "lang"
            lang = node.get_language_code(document_language)
            # use alternative form if `smart-quotes` setting starts with "alt":
            if alternative:
                if '-x-altquot' in lang:
                    lang = lang.replace('-x-altquot', '')
                else:
                    lang += '-x-altquot'
            # drop unsupported subtags:
            for tag in utils.normalize_language_tag(lang):
                if tag in smartquotes.smartchars.quotes:
                    lang = tag
                    break
            else: # language not supported: (keep ASCII quotes)
                if lang not in self.unsupported_languages:
                    self.document.reporter.warning('No smart quotes '
                        'defined for language "%s".'%lang, base_node=node)
                self.unsupported_languages.add(lang)
                lang = ''

            # Iterator educating quotes in plain text:
            # (see "utils/smartquotes.py" for the attribute setting)
            teacher = smartquotes.educate_tokens(self.get_tokens(txtnodes),
                                attr=self.smartquotes_action, language=lang)

            for txtnode, newtext in zip(txtnodes, teacher):
                txtnode.parent.replace(txtnode, nodes.Text(newtext, 
                                       rawsource=txtnode.rawsource))

        self.unsupported_languages = set() # reset 
开发者ID:QData,项目名称:deepWordBug,代码行数:62,代码来源:universal.py


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