本文整理汇总了Python中babel._compat.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_decimal_formats
def parse_decimal_formats(data, tree):
decimal_formats = data.setdefault('decimal_formats', {})
for df_elem in tree.findall('.//decimalFormats'):
if _should_skip_number_elem(data, df_elem): # TODO: Support other number systems
continue
for elem in df_elem.findall('./decimalFormatLength'):
length_type = elem.attrib.get('type')
if _should_skip_elem(elem, length_type, decimal_formats):
continue
if elem.findall('./alias'):
# TODO map the alias to its target
continue
for pattern_el in elem.findall('./decimalFormat/pattern'):
pattern_type = pattern_el.attrib.get('type')
pattern = numbers.parse_pattern(text_type(pattern_el.text))
if pattern_type:
# This is a compact decimal format, see:
# https://www.unicode.org/reports/tr35/tr35-45/tr35-numbers.html#Compact_Number_Formats
# These are mapped into a `compact_decimal_formats` dictionary
# with the format {length: {count: {multiplier: pattern}}}.
# TODO: Add support for formatting them.
compact_decimal_formats = data.setdefault('compact_decimal_formats', {})
length_map = compact_decimal_formats.setdefault(length_type, {})
length_count_map = length_map.setdefault(pattern_el.attrib['count'], {})
length_count_map[pattern_type] = pattern
else:
# Regular decimal format.
decimal_formats[length_type] = pattern
示例2: parse_currency_formats
def parse_currency_formats(data, tree):
currency_formats = data.setdefault('currency_formats', {})
for currency_format in tree.findall('.//currencyFormats'):
if _should_skip_number_elem(data, currency_format): # TODO: Support other number systems
continue
for length_elem in currency_format.findall('./currencyFormatLength'):
curr_length_type = length_elem.attrib.get('type')
for elem in length_elem.findall('currencyFormat'):
type = elem.attrib.get('type')
if curr_length_type:
# Handle `<currencyFormatLength type="short">`, etc.
# TODO(3.x): use nested dicts instead of colon-separated madness
type = '%s:%s' % (type, curr_length_type)
if _should_skip_elem(elem, type, currency_formats):
continue
for child in elem.getiterator():
if child.tag == 'alias':
currency_formats[type] = Alias(
_translate_alias(['currency_formats', elem.attrib['type']],
child.attrib['path'])
)
elif child.tag == 'pattern':
pattern = text_type(child.text)
currency_formats[type] = numbers.parse_pattern(pattern)
示例3: parse_unit_patterns
def parse_unit_patterns(data, tree):
unit_patterns = data.setdefault('unit_patterns', {})
for elem in tree.findall('.//units/unitLength'):
unit_length_type = elem.attrib['type']
for unit in elem.findall('unit'):
unit_type = unit.attrib['type']
for pattern in unit.findall('unitPattern'):
box = unit_type
box += ':' + unit_length_type
unit_patterns.setdefault(box, {})[pattern.attrib['count']] = text_type(pattern.text)
for unit in elem.findall('compoundUnit'):
unit_type = unit.attrib['type']
for pattern in unit.findall('compoundUnitPattern'):
box = 'compound:' + unit_type
box += ':' + unit_length_type
unit_patterns[box] = text_type(pattern.text)
示例4: parse_percent_formats
def parse_percent_formats(data, tree):
percent_formats = data.setdefault('percent_formats', {})
for elem in tree.findall('.//percentFormats/percentFormatLength'):
type = elem.attrib.get('type')
if _should_skip_elem(elem, type, percent_formats):
continue
pattern = text_type(elem.findtext('percentFormat/pattern'))
percent_formats[type] = numbers.parse_pattern(pattern)
示例5: parse_currency_names
def parse_currency_names(data, tree):
currency_names = data.setdefault('currency_names', {})
currency_names_plural = data.setdefault('currency_names_plural', {})
currency_symbols = data.setdefault('currency_symbols', {})
for elem in tree.findall('.//currencies/currency'):
code = elem.attrib['type']
for name in elem.findall('displayName'):
if ('draft' in name.attrib) and code in currency_names:
continue
if 'count' in name.attrib:
currency_names_plural.setdefault(code, {})[
name.attrib['count']] = text_type(name.text)
else:
currency_names[code] = text_type(name.text)
# TODO: support choice patterns for currency symbol selection
symbol = elem.find('symbol')
if symbol is not None and 'draft' not in symbol.attrib and 'choice' not in symbol.attrib:
currency_symbols[code] = text_type(symbol.text)
示例6: parse_currency_unit_patterns
def parse_currency_unit_patterns(data, tree):
currency_unit_patterns = data.setdefault('currency_unit_patterns', {})
for currency_formats_elem in tree.findall('.//currencyFormats'):
if _should_skip_number_elem(data, currency_formats_elem): # TODO: Support other number systems
continue
for unit_pattern_elem in currency_formats_elem.findall('./unitPattern'):
count = unit_pattern_elem.attrib['count']
pattern = text_type(unit_pattern_elem.text)
currency_unit_patterns[count] = pattern
示例7: parse_date_fields
def parse_date_fields(data, tree):
date_fields = data.setdefault('date_fields', {})
for elem in tree.findall('.//dates/fields/field'):
field_type = elem.attrib['type']
date_fields.setdefault(field_type, {})
for rel_time in elem.findall('relativeTime'):
rel_time_type = rel_time.attrib['type']
for pattern in rel_time.findall('relativeTimePattern'):
type_dict = date_fields[field_type].setdefault(rel_time_type, {})
type_dict[pattern.attrib['count']] = text_type(pattern.text)
示例8: parse_number_symbols
def parse_number_symbols(data, tree):
number_symbols = data.setdefault('number_symbols', {})
for symbol_elem in tree.findall('.//numbers/symbols'):
if _should_skip_number_elem(data, symbol_elem): # TODO: Support other number systems
continue
for elem in symbol_elem.findall('./*'):
if _should_skip_elem(elem):
continue
number_symbols[elem.tag] = text_type(elem.text)
示例9: parse_decimal_formats
def parse_decimal_formats(data, tree):
decimal_formats = data.setdefault('decimal_formats', {})
for elem in tree.findall('.//decimalFormats/decimalFormatLength'):
type = elem.attrib.get('type')
if _should_skip_elem(elem, type, decimal_formats):
continue
if elem.findall('./alias'):
# TODO map the alias to its target
continue
pattern = text_type(elem.findtext('./decimalFormat/pattern'))
decimal_formats[type] = numbers.parse_pattern(pattern)
示例10: _extract_plural_rules
def _extract_plural_rules(file_path):
rule_dict = {}
prsup = parse(file_path)
for elem in prsup.findall('.//plurals/pluralRules'):
rules = []
for rule in elem.findall('pluralRule'):
rules.append((rule.attrib['count'], text_type(rule.text)))
pr = PluralRule(rules)
for locale in elem.attrib['locales'].split():
rule_dict[locale] = pr
return rule_dict
示例11: _set_locale
def _set_locale(self, locale):
if locale is None:
self._locale_identifier = None
self._locale = None
return
if isinstance(locale, Locale):
self._locale_identifier = text_type(locale)
self._locale = locale
return
if isinstance(locale, string_types):
self._locale_identifier = text_type(locale)
try:
self._locale = Locale.parse(locale)
except UnknownLocaleError:
self._locale = None
return
raise TypeError('`locale` must be a Locale, a locale identifier string, or None; got %r' % locale)
示例12: parse_currency_names
def parse_currency_names(data, tree):
currency_names = data.setdefault('currency_names', {})
currency_names_plural = data.setdefault('currency_names_plural', {})
currency_symbols = data.setdefault('currency_symbols', {})
for elem in tree.findall('.//currencies/currency'):
code = elem.attrib['type']
for name in elem.findall('displayName'):
if ('draft' in name.attrib) and code in currency_names:
continue
if 'count' in name.attrib:
currency_names_plural.setdefault(code, {})[
name.attrib['count']] = text_type(name.text)
else:
currency_names[code] = text_type(name.text)
for symbol in elem.findall('symbol'):
if 'draft' in symbol.attrib or 'choice' in symbol.attrib: # Skip drafts and choice-patterns
continue
if symbol.attrib.get('alt'): # Skip alternate forms
continue
currency_symbols[code] = text_type(symbol.text)
示例13: parse_scientific_formats
def parse_scientific_formats(data, tree):
scientific_formats = data.setdefault('scientific_formats', {})
for sf_elem in tree.findall('.//scientificFormats'):
if _should_skip_number_elem(data, sf_elem): # TODO: Support other number systems
continue
for elem in sf_elem.findall('./scientificFormatLength'):
type = elem.attrib.get('type')
if _should_skip_elem(elem, type, scientific_formats):
continue
pattern = text_type(elem.findtext('scientificFormat/pattern'))
scientific_formats[type] = numbers.parse_pattern(pattern)
示例14: parse_calendar_periods
def parse_calendar_periods(data, calendar):
# AM/PM
periods = data.setdefault('periods', {})
for day_period_width in calendar.findall(
'dayPeriods/dayPeriodContext/dayPeriodWidth'
):
if day_period_width.attrib['type'] == 'wide':
for day_period in day_period_width.findall('dayPeriod'):
if 'alt' not in day_period.attrib:
periods[day_period.attrib['type']] = text_type(
day_period.text)
示例15: parse_calendar_periods
def parse_calendar_periods(data, calendar):
# Day periods (AM/PM/others)
periods = data.setdefault('day_periods', {})
for day_period_ctx in calendar.findall('dayPeriods/dayPeriodContext'):
ctx_type = day_period_ctx.attrib["type"]
for day_period_width in day_period_ctx.findall('dayPeriodWidth'):
width_type = day_period_width.attrib["type"]
dest_dict = periods.setdefault(ctx_type, {}).setdefault(width_type, {})
for day_period in day_period_width.findall('dayPeriod'):
period_type = day_period.attrib['type']
if 'alt' not in day_period.attrib:
dest_dict[period_type] = text_type(day_period.text)