Package zope :: Package i18n :: Package locales :: Class LocaleDates
[show private | hide private]
[frames | no frames]

Type 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
  getFormatter(self, category, length, name, calendar)
See zope.i18n.interfaces.locales.ILocaleDates
    Inherited from AttributeInheritance
  __getattr__(self, name)
See zope.i18n.interfaces.locales.ILocaleInheritance
  __setattr__(self, name, value)
See zope.i18n.interfaces.locales.ILocaleInheritance
    Inherited from Inheritance
  getInheritedSelf(self)
See zope.i18n.interfaces.locales.ILocaleInheritance
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __str__(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__

Type:
Implements
Value:
<implementedBy zope.i18n.locales.LocaleDates>                          

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0xb5ed7c6c>       

Generated by Epydoc 2.1 on Fri Jun 24 12:01:22 2005 http://epydoc.sf.net