开发者

Query with toLocalizedTime in Plone

开发者 https://www.devze.com 2022-12-20 22:42 出处:网络
I\'m using toLocalizedTime to output a date, as below <span ta开发者_开发百科l:content=\"python:here.toLocalisedTime(date.get(\'start_date\'))\"/>

I'm using toLocalizedTime to output a date, as below

<span ta开发者_开发百科l:content="python:here.toLocalisedTime(date.get('start_date'))"/>

This outputs eg. 2007/08/02, I'm just curious as to how one would alter the output so that it reads 02/08/2007

I'm not having much luck finding much info on toLocalizedTime, would someone point me in the right direction?


This depends on whether you have English selected as the site language (Site Setup >> Language). If so, then the default settings are used. You can change the defaults by dropping down into the ZMI, then into 'portal_properties', then 'site_properties'. The fields to change are either 'localTimeFormat' or 'localLongTimeFormat' depending on whether you pass in 'long_format=1' to the toLocalisedTime function.

If on the other hand, you have translations set up, the format may instead be pulled from the translation file for the locale selected. I'm not sure what is the easy way to change the format in this case (other than switching the site back to English). I guess you can register your own translation file but I've never needed to do that so you're going to have to look up the details.

Date string formatting follows the Python rules (http://docs.python.org/library/time.html#time.strftime).


Perhaps even more detail than you need:

here.toLocalizedTime()

is defined in the plone browser view at...

CMFPlone/browser/ploneview.py

which looks up the 'translation_service' utility, to call its 'ulocalized_time' function, defined at...

CMFPlone/TranslationServiceTool.py

which itself calls the 'ulocalized_time' function defined at...

CMFPlone/i18nl10n.py

As always, you can learn interesting things by grepping the source code ;-)


For an up to date answer for Plone 4.3 (after going through the source code)

These fields are now in the registry found at: http://localhost:8080/yoursite/portal_registry

Then filter on "i18nl10n", which should give you the 4 fields you need to change.

0

精彩评论

暂无评论...
验证码 换一张
取 消