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


Python Locale.get_display_name方法代码示例

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


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

示例1: _set_language_dropdown_values

# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import get_display_name [as 别名]
    def _set_language_dropdown_values(self, initial_locale=None):
        log.debug('Setting languages dropdown menu for %r' % initial_locale)
        available_locales = self._find_available_locales()
        locale = Locale(initial_locale)
        if not locale:
            locale = Locale.parse(initial_locale)
        languages = []
        current_lang = h.get_lang()[0]
        for loc in available_locales:
            selected = False
            if loc == current_lang:
                selected = True

            local_locale = Locale(loc)
            if not local_locale:
                local_locale = Locale.parse(loc)
            languages.append((loc, local_locale.get_display_name(locale), selected))
        return locale, languages

        for loc, territory in available_locales:
            selected = False
            language = locale.languages[loc].capitalize()
            if territory:
                country = u'(%s)' % locale.territories[territory]
                value = ['%s_%s' % (loc, territory),
                         u'%s %s' % (language, country)]
                if value[0] == current_lang:
                    selected = True
            else:
                value = [loc, language]
                if value[0] == current_lang:
                    selected = True
            languages.append( value + [selected])
        return locale, languages
开发者ID:UfSoft,项目名称:oil,代码行数:36,代码来源:base.py

示例2: convert_bucket

# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import get_display_name [as 别名]
def convert_bucket(facet, bucket):
    key = bucket.get('key_as_string', bucket.get('key'))
    data = {
        'count': bucket.get('doc_count'),
        'id': key,
        'label': key,
    }

    if facet == 'languages':
        try:
            locale = Locale(key.strip().lower())
            data['label'] = locale.get_display_name('en_US')
        except:
            pass
    elif facet == 'countries' and key is not None:
        try:
            country = countries.get(alpha2=key.strip().upper())
            data['label'] = country.name
        except:
            pass
    return data
开发者ID:andkamau,项目名称:aleph,代码行数:23,代码来源:facets.py

示例3: test_get_display_name

# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import get_display_name [as 别名]
 def test_get_display_name(self):
     zh_CN = Locale('zh', 'CN', script='Hans')
     assert zh_CN.get_display_name('en') == 'Chinese (Simplified, China)'
开发者ID:dstanek,项目名称:babel,代码行数:5,代码来源:test_core.py

示例4: expand_macro

# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import get_display_name [as 别名]
    def expand_macro(self, formatter, name, arguments):
        """Returns macro content."""
        env = self.env
        req = formatter.req
        tz = req.tz

        # Parse arguments from macro invocation.
        args, kwargs = parse_args(arguments, strict=False)

        # Enable week number display regardless of argument position.
        week_pref = "w" in args and args.pop(args.index("w"))

        week_pref = week_pref and week_pref or kwargs.get("w")
        week_start = None
        week_num_start = None
        # Parse per-instance week calculation rules, if available.
        if week_pref:
            if ":" not in week_pref:
                # Treat undelimitted setting as week start.
                week_pref += ":"
            w_start, wn_start = week_pref.split(":")
            try:
                week_start = int(w_start)
            except ValueError:
                week_start = None
            else:
                week_start = week_start > -1 and week_start < 7 and week_start or None
            try:
                week_num_start = int(wn_start)
            except ValueError:
                week_num_start = None
            else:
                week_num_start = week_num_start in (1, 4, 7) and week_num_start or None

        # Respect user's locale, if available.
        try:
            locale = Locale.parse(str(req.locale))
        except (AttributeError, UnknownLocaleError):
            # Attribute 'req.locale' vailable since Trac 0.12.
            locale = None
        if has_babel:
            if locale:
                if not locale.territory:
                    # Search first locale, which has the same `language` and
                    # territory in preferred languages.
                    for l in req.languages:
                        l = l.replace("-", "_").lower()
                        if l.startswith(locale.language.lower() + "_"):
                            try:
                                l = Locale.parse(l)
                                if l.territory:
                                    locale = l
                                    break  # first one rules
                            except UnknownLocaleError:
                                pass
                if not locale.territory and locale.language in LOCALE_ALIASES:
                    locale = Locale.parse(LOCALE_ALIASES[locale.language])
            else:
                # Default fallback.
                locale = Locale("en", "US")
            env.log.debug("Locale setting for wiki calendar: %s" % locale.get_display_name("en"))
        if not week_start:
            if week_pref and week_pref.lower().startswith("iso"):
                week_start = 0
                week_num_start = 4
            elif has_babel:
                week_start = locale.first_week_day
            else:
                import calendar

                week_start = calendar.firstweekday()
        # ISO calendar will remain as default.
        if not week_num_start:
            if week_start == 6:
                week_num_start = 1
            else:
                week_num_start = 4
        env.log.debug(
            "Effective settings: first_week_day=%s, " "1st_week_of_year_rule=%s" % (week_start, week_num_start)
        )

        # Find year and month of interest.
        year = req.args.get("year")
        # Not clicked on any previous/next button, next look for macro args.
        if not year and len(args) >= 1 and args[0] != "*":
            year = args[0]
        year = year and year.isnumeric() and int(year) or None

        month = req.args.get("month")
        # Not clicked on any previous/next button, next look for macro args.
        if not month and len(args) >= 2 and args[1] != "*":
            month = args[1]
        month = month and month.isnumeric() and int(month) or None

        now = datetime.now(tz)
        # Force offset from start-of-day to avoid a false 'today' marker,
        # but use it only on request of different month/year.
        now.replace(second=1)
        today = None
        if month and month != now.month:
#.........这里部分代码省略.........
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:103,代码来源:macros.py


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