:type: `unicode`
""")
+ #{ General Locale Display Names
+
def languages(self):
return self._data['languages']
languages = property(languages, doc="""\
:type: `dict`
""")
+ #{ Number Formatting
+
def number_symbols(self):
return self._data['number_symbols']
number_symbols = property(number_symbols, doc="""\
:type: `dict`
""")
+ #{ Calendar Information and Date Formatting
+
def periods(self):
return self._data['periods']
periods = property(periods, doc="""\
:type: `dict`
""")
+ def first_week_day(self):
+ return self._data['week_data']['first_day']
+ first_week_day = property(first_week_day, doc="""\
+ The first day of a week.
+
+ >>> Locale('de', 'DE').first_week_day
+ 1
+ >>> Locale('en', 'US').first_week_day
+ 7
+
+ :type: `int`
+ """)
+
+ def weekend_start(self):
+ return self._data['week_data']['weekend_start']
+ weekend_start = property(weekend_start, doc="""\
+ The day the weekend starts.
+
+ >>> Locale('de', 'DE').weekend_start
+ 6
+
+ :type: `int`
+ """)
+
+ def weekend_end(self):
+ return self._data['week_data']['weekend_end']
+ weekend_end = property(weekend_end, doc="""\
+ The day the weekend ends.
+
+ >>> Locale('de', 'DE').weekend_end
+ 7
+
+ :type: `int`
+ """)
+
+ def min_week_days(self):
+ return self._data['week_data']['min_days']
+ min_week_days = property(min_week_days, doc="""\
+ The minimum number of days in a week so that the week is counted as the
+ first week of a year or month.
+
+ >>> Locale('de', 'DE').min_week_days
+ 4
+
+ :type: `int`
+ """)
+
def date_formats(self):
return self._data['date_formats']
date_formats = property(date_formats, doc="""\
return self.format(self.value.day, len(name))
elif name[0] == 'E':
return self.format_weekday(len(name))
+ elif name[0] == 'e':
+ return self.format_weekday(len(name), add_firstday=True)
elif name[0] == 'c':
return self.format_weekday(len(name), context='stand-alone')
elif name[0] == 'a':
width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[num]
return get_month_names(width, context, self.locale)[self.value.month]
- def format_weekday(self, num, context='format'):
+ def format_weekday(self, num, add_firstday=False, context='format'):
width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[max(3, num)]
weekday = self.value.weekday() + 1
+ if add_firstday:
+ weekday += self.locale.first_week_day
return get_day_names(width, context, self.locale)[weekday]
def format_period(self):
from babel.dates import parse_pattern
+weekdays = {'mon': 1, 'tue': 2, 'wed': 3, 'thu': 4, 'fri': 5, 'sat': 6,
+ 'sun': 7}
+
+try:
+ any
+except NameError:
+ def any(iterable):
+ return filter(None, list(iterable))
+
def _parent(locale):
parts = locale.split('_')
if len(parts) == 1:
destdir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
'..', 'babel', 'localedata')
+ sup = parse(os.path.join(srcdir, 'supplemental', 'supplementalData.xml'))
+
+ # build a territory containment mapping for inheritance
+ regions = {}
+ for elem in sup.findall('//territoryContainment/group'):
+ regions[elem.attrib['type']] = elem.attrib['contains'].split()
+ from pprint import pprint
+
+ # Resolve territory containment
+ territory_containment = {}
+ region_items = regions.items()
+ region_items.sort()
+ for group, territory_list in region_items:
+ for territory in territory_list:
+ containers = territory_containment.setdefault(territory, set([]))
+ if group in territory_containment:
+ containers |= territory_containment[group]
+ containers.add(group)
+
filenames = os.listdir(os.path.join(srcdir, 'main'))
filenames.remove('root.xml')
filenames.sort(lambda a,b: len(a)-len(b))
data.update(copy.deepcopy(dicts[_parent(stem)]))
tree = parse(os.path.join(srcdir, 'main', filename))
+ language = None
+ elem = tree.find('//identity/language')
+ if elem is not None:
+ language = elem.attrib['type']
+ print>>sys.stderr, ' Language: %r' % language
+
+ territory = None
+ elem = tree.find('//identity/territory')
+ if elem is not None:
+ territory = elem.attrib['type']
+ print>>sys.stderr, ' Territory: %r' % territory
+ regions = territory_containment.get(territory, [])
+ print>>sys.stderr, ' Regions: %r' % regions
+
# <localeDisplayNames>
territories = data.setdefault('territories', {})
# <dates>
+ week_data = data.setdefault('week_data', {})
+ supelem = sup.find('//weekData')
+
+ for elem in supelem.findall('minDays'):
+ territories = elem.attrib['territories'].split()
+ if territory in territories or any([r in territories for r in regions]):
+ week_data['min_days'] = int(elem.attrib['count'])
+
+ for elem in supelem.findall('firstDay'):
+ territories = elem.attrib['territories'].split()
+ if territory in territories or any([r in territories for r in regions]):
+ week_data['first_day'] = weekdays[elem.attrib['day']]
+
+ for elem in supelem.findall('weekendStart'):
+ territories = elem.attrib['territories'].split()
+ if territory in territories or any([r in territories for r in regions]):
+ week_data['weekend_start'] = weekdays[elem.attrib['day']]
+
+ for elem in supelem.findall('weekendEnd'):
+ territories = elem.attrib['territories'].split()
+ if territory in territories or any([r in territories for r in regions]):
+ week_data['weekend_end'] = weekdays[elem.attrib['day']]
+
time_zones = data.setdefault('time_zones', {})
for elem in tree.findall('//timeZoneNames/zone'):
time_zones[elem.tag] = unicode(elem.findtext('displayName'))
for width in ctxt.findall('dayWidth'):
widths = ctxts.setdefault(width.attrib['type'], {})
for elem in width.findall('day'):
- dtype = {'mon': 1, 'tue': 2, 'wed': 3, 'thu': 4,
- 'fri': 5, 'sat': 6, 'sun': 7}[elem.attrib['type']]
+ dtype = weekdays[elem.attrib['type']]
if 'draft' in elem.attrib and dtype in widths:
continue
widths[dtype] = unicode(elem.text)