[Zope-CMF] Re: Internationlisation question

Doyon, Jean-Francois jdoyon at NRCan.gc.ca
Mon Feb 12 08:41:05 EST 2007


What Philip said :)

Note that i18n:target is broken ... See
http://zope.org/Collectors/Zope/1114 for a potential solution.

If you try to use the currency functionality, you may also run into
problems ... In that case, see this post:
http://mail.zope.org/pipermail/zope3-users/2006-December/005145.html

Cheers,
J.F. 

-----Original Message-----
From: zope-cmf-bounces at lists.zope.org
[mailto:zope-cmf-bounces at lists.zope.org] On Behalf Of Philipp von
Weitershausen
Sent: February 11, 2007 4:27 PM
To: zope-cmf at zope.org
Subject: [Zope-CMF] Re: Internationlisation question

Charlie Clark wrote:
>> Zope 3 provides all sorts of localization functionality, including 
>> numbers, currency and calendaring.
> Look in zope.i18n.locales ...
> 
> Yes, I can see what's there but I do not seem to be able to call it 
> from a page template. If I try the following example from
> 
> http://wiki.zope.org/zope3/ZPTInternationalizationExamples
> 
>   <p i18n:translate="longDateTime"
>      i18n:domain="string:calendar" i18n:target="string:de"
>      i18n:data="python:DateTime()">
>     Based on what the id specifies, the date time object is returned
in
>     typical German format: Montag, 1. Januar 2001 (example)
>   </p>

This is quite outdated. It doesn't surprise me you're getting an error
here.

Like Jean-Francois said, zope.i18n.locales has some good support for
formatting datetime values (the Python variant, not Zope's DateTime
variant). In Zope 3, this functionality is available through
request.locale. In Zope 2, you will have to create the locale object
yourself like so:

  from zope.i18n.interfaces import IUserPreferredLanguages
  from zope.i18n.locales import locales

  languages = IUserPreferredLanguages(request)
  langs = languages.getPreferredLanguages()
  if langs:
      parts = (langs[0].split('-') + [None, None])[:3]
  else:
      parts = (None, None, None)

  locale = locales.getLocale(*parts)

Then you can format datetimes such as the 'modified' variable in the
below example like so:

   <p i18n:translate="" tal:condition="modified"
      tal:define="formatter
python:locale.dates.getFormatter('dateTime')">
     Last modified on
     <span i18n:name="modified_date"
           tal:replace="python:formatter.format(modified)" />
   </p>

My book explains all of this in detail. I suggest picking up a copy :)


--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5

_______________________________________________
Zope-CMF maillist  -  Zope-CMF at lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


More information about the Zope-CMF mailing list