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

Python data.simplify_to_common函数代码示例

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

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



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

示例1: get_alt_src_langs

def get_alt_src_langs(request, user, translation_project):
    language = translation_project.language
    project = translation_project.project
    source_language = project.source_language

    langs = user.alt_src_langs.exclude(
        id__in=(language.id, source_language.id)
    ).filter(translationproject__project=project)

    if not user.alt_src_langs.count():
        from pootle_language.models import Language
        accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')

        for accept_lang, unused in parse_accept_lang_header(accept):
            if accept_lang == '*':
                continue

            simplified = data.simplify_to_common(accept_lang)
            normalized = to_locale(data.normalize_code(simplified))
            code = to_locale(accept_lang)
            if (normalized in
                    ('en', 'en_US', source_language.code, language.code) or
                code in ('en', 'en_US', source_language.code, language.code)):
                continue

            langs = Language.objects.filter(
                code__in=(normalized, code),
                translationproject__project=project,
            )
            if langs.count():
                break

    return langs
开发者ID:adamchainz,项目名称:pootle,代码行数:33,代码来源:views.py


示例2: get_alt_src_langs

def get_alt_src_langs(request, profile, translation_project):
    language = translation_project.language
    project = translation_project.project
    source_language = project.source_language

    langs = profile.alt_src_langs.exclude(id__in=(language.id, source_language.id)).filter(
        translationproject__project=project
    )

    if not profile.alt_src_langs.count():
        from pootle_language.models import Language

        accept = request.META.get("HTTP_ACCEPT_LANGUAGE", "")
        for accept_lang, unused in parse_accept_lang_header(accept):
            if accept_lang == "*":
                continue
            normalized = to_locale(data.normalize_code(data.simplify_to_common(accept_lang)))
            code = to_locale(accept_lang)
            if normalized in ("en", "en_US", source_language.code, language.code) or code in (
                "en",
                "en_US",
                source_language.code,
                language.code,
            ):
                continue
            langs = Language.objects.filter(code__in=(normalized, code), translationproject__project=project)
            if langs.count():
                break
    return langs
开发者ID:julen,项目名称:pootle,代码行数:29,代码来源:views.py


示例3: get_alt_src_langs

def get_alt_src_langs(request, user, translation_project):
    if request.user.is_anonymous:
        return
    language = translation_project.language
    project = translation_project.project
    source_language = project.source_language
    langs = list(
        user.alt_src_langs.exclude(
            id__in=(language.id, source_language.id)
        ).filter(
            translationproject__project=project))
    if langs:
        return langs
    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    for accept_lang, __ in parse_accept_lang_header(accept):
        if accept_lang == '*':
            continue
        normalized = to_locale(
            data.normalize_code(
                data.simplify_to_common(accept_lang)))
        code = to_locale(accept_lang)
        is_source_lang = any(
            langcode in ('en', 'en_US', source_language.code, language.code)
            for langcode in [code, normalized])
        if is_source_lang:
            continue

        langs = list(
            Language.objects.filter(
                code__in=(normalized, code),
                translationproject__project=project))
        if langs:
            return langs
开发者ID:arky,项目名称:pootle,代码行数:33,代码来源:views.py


示例4: lang_to_table

def lang_to_table(code):
    # normalize to simplest form
    result = data.simplify_to_common(code)
    if data.langcode_ire.match(result):
        # normalize to legal table name
        return result.replace("-", "_").replace("@", "_").lower()
    # illegal language name
    return None
开发者ID:cc-archive,项目名称:pootle,代码行数:8,代码来源:tmdb.py


示例5: get_language_supported

def get_language_supported(lang_code, supported):
    normalized = data.normalize_code(data.simplify_to_common(lang_code))
    if normalized in supported:
        return normalized

    # FIXME: horribly slow way of dealing with languages with @ in them
    for lang in supported.keys():
        if normalized == data.normalize_code(lang):
            return lang

    return None
开发者ID:arky,项目名称:pootle,代码行数:11,代码来源:override.py


示例6: __init__

    def __init__(self, filename = None):
        """Load settings, using the given or default filename"""
        if not filename:
            self.filename = os.path.join(get_config_dir(), default_config_name)
        else:
            self.filename = filename
            if not os.path.isfile(self.filename):
                raise Exception

        self.language["targetlang"] = data.simplify_to_common(get_locale_lang())
        self.config = ConfigParser.RawConfigParser()
        self.read()
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:12,代码来源:pan_app.py


示例7: lang_to_table

def lang_to_table(code):
    if code in _table_name_cache:
        return _table_name_cache[code]
    # Normalize to simplest form.
    result = data.simplify_to_common(code)
    if data.langcode_ire.match(result):
        # Normalize to legal table name.
        table_name = result.replace("-", "_").replace("@", "_").lower()
        _table_name_cache[code] = table_name
        return table_name
    # Illegal language name.
    return None
开发者ID:viperfx,项目名称:GSOC,代码行数:12,代码来源:tmdb.py


示例8: get_locale_lang

def get_locale_lang():
    #if we wanted to determine the UI language ourselves, this should work:
    #lang = locale.getdefaultlocale(('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'))[0]
    #if not lang and sys.platform == "darwin":
    #   lang = osx_lang()

    # guess default target lang based on locale, simplify to commonly used form
    try:
        lang = locale.getdefaultlocale(('LANGUAGE', 'LC_ALL', 'LANG'))[0]
        if not lang and sys.platform == "darwin":
           lang = osx_lang()
        if lang:
            return data.simplify_to_common(lang)
    except Exception, e:
        logging.warning("%s", e)
开发者ID:denji,项目名称:virtaal,代码行数:15,代码来源:pan_app.py


示例9: get_alt_src_langs

def get_alt_src_langs(request, profile, language):
    langs = profile.alt_src_langs.exclude(id=language.id)
    if not langs.count():
        accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
        codes = []
        for accept_lang, unused in parse_accept_lang_header(accept):
            if accept_lang == '*':
                continue
            normalized = to_locale(data.normalize_code(data.simplify_to_common(accept_lang)))
            if normalized in ['en_US', 'en', language.code]:
                continue
            codes.append(normalized)
        if codes:
            from pootle_language.models import Language
            langs = Language.objects.filter(code__in=codes)
    return langs
开发者ID:mellterm,项目名称:pootle,代码行数:16,代码来源:views.py


示例10: get_lang_from_http_header

def get_lang_from_http_header(request, supported):
    """If the user's browser sends a list of preferred languages in the
    HTTP_ACCEPT_LANGUAGE header, parse it into a list. Then walk through
    the list, and for each entry, we check whether we have a matching
    pootle translation project. If so, we return it.

    If nothing is found, return None."""
    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    for accept_lang, unused in trans_real.parse_accept_lang_header(accept):
        if accept_lang == '*':
            return None
        normalized = data.normalize_code(data.simplify_to_common(accept_lang, supported))
        if normalized in ['en-us', 'en']:
            return None
        if normalized in supported:
            return normalized

        #FIXME: horribly slow way of dealing with languages with @ in them
        for lang in supported.keys():
            if normalized == data.normalize_code(lang):
                return lang
    return None
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:22,代码来源:override.py


示例11: load

    def load(self, langcode):
        # FIXME: what if we get language code with different capitalization?
        if langcode not in self.languages:
            try:
                langcode = self._match_normalized_langcode(langcode)
            except ValueError:
                langcode = data.simplify_to_common(langcode)
                if langcode not in self.languages:
                    try:
                        langcode = self._match_normalized_langcode(langcode)
                    except ValueError:
                        logging.info("unkown language %s" % langcode)
                        self.name = langcode
                        self.code = langcode
                        self.nplurals = 0
                        self.plural = ""
                        return

        self.name = gettext_lang(self.languages[langcode][0])
        self.code = langcode
        self.nplurals = self.languages[langcode][1]
        self.plural = self.languages[langcode][2]
开发者ID:scootergrisen,项目名称:virtaal,代码行数:22,代码来源:langmodel.py


示例12: test_simplify_to_common

def test_simplify_to_common():
    """test language code simplification"""
    assert data.simplify_to_common("af_ZA") == "af"
    assert data.simplify_to_common("pt_PT") == "pt"
    assert data.simplify_to_common("pt_BR") == "pt_BR"
开发者ID:onia,项目名称:translate,代码行数:5,代码来源:test_data.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python factory.getlanguage函数代码示例发布时间:2022-05-27
下一篇:
Python data.normalize_code函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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