Am 11.02.2007 um 22:27 schrieb Philipp von Weitershausen:
My book explains all of this in detail. I suggest picking up a copy :)
As luck would have it there was actually a copy in the shop so I'll
be leafing through it in days to come.
As previously noted (although I'm waiting for my mails to come
through on the mailing list - they're being rejected by zope.com for
some reason - I wasn't quite able to use your example but had to put
the work into an ExternalMethod
from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.locales import locales
import datetime, mx.DateTime as DateTime
def format(request, zopedate, what='date', fmt='long'):
"""Accepts a Zope DateTime or mx.DateTime object and returns the
localised form. Default is long date time."""
languages = IUserPreferredLanguages(request)
langs = languages.getPreferredLanguages()
parts = (langs.split('-') + [None, None])[:3]
parts = (None, None, None)
locale = locales.getLocale(*parts)
formatter = locale.dates.getFormatter(what, fmt)
if isinstance(zopedate, DateTime.DateTimeType):
y, m, d, H, M, S = zopedate.tuple()[:6]
y, m, d, H, M, S = zopedate.parts()[:6]
dt = formatter.format(datetime.datetime(y, m, d, H, M, S))
It's interesting to note that a Python datetime type is mandatory. I
know that Marc-André is working mx.DateTime to make it compatible
with Python datetime (essentially it's just missing .weekday but I
was surprised to have problems with Zope DateTime.
And this is called like this
<span tal:content="python: context.scripts.locale(request, dates
['date'], 'date', 'full')" />
ie., I couldn't pack this inside an i18n block as you suggested.
Hopefully I'll find enlightenment in your book! But thanks for the
help thus far.
Zope-CMF maillist - Zope-CMF@lists.zope.org
See http://collector.zope.org/CMF for bug reports and feature requests