| Trees | Index | Help |
|
|---|
| Package zope :: Package i18n :: Package locales :: Class LocaleDates |
|
object --+
|
Inheritance --+
|
AttributeInheritance --+
|
LocaleDates
Simple ILocaleDates implementation that can inherit data from other locales.
Examples:
>>> from zope.i18n.tests.test_formats import LocaleCalendarStub as Stub
>>> from datetime import datetime, date, time
>>> dates = LocaleDates()
>>> cal = LocaleCalendar('gregorian')
>>> cal.months = Stub.months
>>> cal.days = Stub.days
>>> cal.am = Stub.am
>>> cal.pm = Stub.pm
>>> cal.eras = Stub.eras
>>> cal.week = {'firstDay': 1, 'minDays': 1}
>>> dates.calendars = {'gregorian': cal}
Setting up and accessing date format through a specific length (very
common scenario)
>>> fulllength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'EEEE, d. MMMM yyyy'
>>> fulllength.formats = {None: format}
>>> mediumlength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'dd.MM.yyyy'
>>> mediumlength.formats = {None: format}
>>> cal.dateFormats = {'full': fulllength, 'medium': mediumlength}
>>> cal.defaultDateFormat = 'medium'
>>> formatter = dates.getFormatter('date') >>> formatter.format(date(2004, 02, 04)) u'04.02.2004'
>>> formatter = dates.getFormatter('date', length='full') >>> formatter.format(date(2004, 02, 04)) u'Mittwoch, 4. Februar 2004'Let's also test the time formatter
>>> fulllength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u"H:mm' Uhr 'z"
>>> fulllength.formats = {None: format}
>>> mediumlength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'HH:mm:ss'
>>> mediumlength.formats = {None: format}
>>> cal.timeFormats = {'full': fulllength, 'medium': mediumlength}
>>> cal.defaultTimeFormat = 'medium'
>>> formatter = dates.getFormatter('time') >>> formatter.format(time(12, 15, 00)) u'12:15:00'
>>> formatter = dates.getFormatter('time', length='full') >>> formatter.format(time(12, 15, 00)) u'12:15 Uhr +000'The datetime formatter is a bit special, since it is constructed from the other two:
>>> length = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'{1} {0}'
>>> length.formats = {None: format}
>>> cal.dateTimeFormats = {None: length}
>>> formatter = dates.getFormatter('dateTime') >>> formatter.format(datetime(2004, 02, 04, 12, 15, 00)) u'04.02.2004 12:15:00'
>>> formatter = dates.getFormatter('dateTime', length='full') >>> formatter.format(datetime(2004, 02, 04, 12, 15, 00)) u'Mittwoch, 4. Februar 2004 12:15 Uhr +000'Finally, we'll test some invalid input:
>>> dates.getFormatter('timeDate') Traceback (most recent call last): ValueError: Invalid category: timeDate
>>> dates.getFormatter('date', length='superlong') Traceback (most recent call last): ValueError: Invalid format length: superlong
>>> dates.getFormatter('date', calendar='irish-catholic') Traceback (most recent call last): ValueError: Invalid calendar: irish-catholic
| Method Summary | |
|---|---|
See zope.i18n.interfaces.locales.ILocaleDates | |
| Inherited from AttributeInheritance | |
See zope.i18n.interfaces.locales.ILocaleInheritance | |
See zope.i18n.interfaces.locales.ILocaleInheritance | |
| Inherited from Inheritance | |
See zope.i18n.interfaces.locales.ILocaleInheritance | |
| Inherited from object | |
x.__init__(...) initializes x; see x.__class__.__doc__ for signature | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__str__() <==> str(x) | |
| Class Variable Summary | |
|---|---|
Implements |
__implemented__ = <implementedBy zope.i18n.locales.Local...
|
ClassProvides |
__provides__ = <zope.interface.declarations.ClassProvide...
|
| Inherited from Inheritance | |
str |
__name__ = 'Inheritance'
|
NoneType |
__parent__ = None |
ClassProvides |
__providedBy__ = <zope.interface.declarations.ClassProvi...
|
| Method Details |
|---|
getFormatter(self, category, length=None, name=None, calendar=u'gregorian')See zope.i18n.interfaces.locales.ILocaleDates |
| Class Variable Details |
|---|
__implemented__
|
__provides__
|
| Trees | Index | Help |
|
|---|
| Generated by Epydoc 2.1 on Fri Jun 24 12:01:22 2005 | http://epydoc.sf.net |