[Product-Developers] Re: translating a date in a page template

Kees Hink hink at gw20e.com
Mon Mar 23 14:57:36 UTC 2009


Found the strftime() method, but i can't get it to translate the month name:
datetime.strftime('%d %B %Y') yields the date with an English month name ('20
March, 2009 '). How to get that in the portal language?

Maybe i didn't find the documentation you are referring to? I found
http://api.plone.org/Plone/2.1.1/public/DateTime.DateTime.DateTime-class.html
(old) and http://docs.python.org/library/time.html (Zope passes strftime through
to Python's, and i wouldn't want to use the system locale for translated
strings, as it's different from the site language). But none of them
mention translating month names.

Andreas Jung wrote:
> DateTime instance provide the strftime() method (according to the docs).
> 
> -aj
> 
> On Mon, Mar 23, 2009 at 14:21, Kees Hink <hink at gw20e.com
> <mailto:hink-JZa/QnC6/z0AvxtiuMwx3w at public.gmane.org>> wrote:
> 
>     How can i translate a DateTime object from TAL?
> 
>     My use case is a custom content type (AT) which has a DateTime
>     field. I would
>     like to show the date for this field as '%d %B %Y', where %B is the
>     full name of
>     the month in the site's language. (Site language is Dutch, this is
>     also set in
>     portal_languages.)
> 
>     I tried to create a translation using toLocalizedTime()
>      <span tal:define="translation python:
>     context.toLocalizedTime(datetime)"
>          tal:replace="translation" />
>     where 'datetime' is a DateTime object. However, this renders the date in
>     '%d-%m-%Y' format.
> 
>     Possibly related: Dates in document bylines are shown in English. I
>     have set the
>     site language to Dutch and the site property localLongTimeFormat to
>     '%d %B, %Y
>     %I:%M %p'. It shows the right format, but untranslated.
> 
>     setup:
>        *  Plone 3.2.1
>        * CMF 2.1.2
>        * Zope (Zope 2.10.6-final, python 2.4.5, linux2)
>        * Python 2.4.5 (#2, Aug 1 2008, 02:22:02) [GCC 4.3.1]
>        * PIL 1.1.6
> 
>     _______________________________________________
>     Product-Developers mailing list
>     Product-Developers at lists.plone.org
>     <mailto:Product-Developers-G3yHMj00SlOLbbK5bonKug at public.gmane.org>
>     http://lists.plone.org/mailman/listinfo/product-developers
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Product-Developers mailing list
> Product-Developers-G3yHMj00SlOLbbK5bonKug at public.gmane.org
> http://lists.plone.org/mailman/listinfo/product-developers




More information about the Product-Developers mailing list