New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow domain and target_language for dates_for_display #173

agitator opened this Issue Jan 19, 2015 · 2 comments


None yet
2 participants

This comment has been minimized.


thet commented Jan 21, 2015

@agitator and i were investigating a bit. this is the outcome.

in a environment, context and/or requests have sometimes the language not set to what the user expects (e.g. when called by a cron job). the usecase actually just requires a translated start date and start time, this is why i recommend not to use dates_for_display, but another translate function directly. defines date/time related format strings in the plonelocales domain like so:
msgid "date_format_long" msgstr "${d}.${m}.${Y} ${H}:${M}"

which is aweome, except that datetime.strftime cannot use a format string like u"${d}.${m}.${Y} ${H}:${M}" directly. therefore we need Products.CMFPlone.i18nl10.ulocalized_time, which contains a lot of logic to manipulate these message strings. i don't know yet, why this has to be so complicated and why we're not just using strftime compatible formatstrings in plonelocales message catalog. but however.

ulocalized_time uses zope.i18n.translate in three different places. ulocalized_time accepts msgid, domain but not target_language. zope.i18n.translate does accept a target_language.

i recommend to fix ulocalized_time in CMFPlone to accept and use a target_language.

but the solution for our usecase is to copy ulocalized_time and fix it in our cusomized version, just to get the project done.


This comment has been minimized.


thet commented Jan 21, 2015

Much simpler, but also hackish (as it abuses the message strings a bit) solution for this problem:

>>> from datetime import datetime
>>> from zope.i18n import translate
>>> fstr = translate('date_format_long', domain='plonelocales', target_language='de')
>>> fstr
'${d}.${m}.${Y} ${H}:${M}'

>>> ffstr = fstr.replace('$', '%').replace('{', '').replace('}', '')
>>> ffstr
u'%d.%m.%Y %H:%M'

'21.01.2015 16:03'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment