本文整理汇总了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
示例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
示例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)'
示例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:
#.........这里部分代码省略.........