Thursday, March 1, 2012

humanized date range and translation

Hello,

I am working on a Django application for handling events with schedules. Basically an event has a starting and ending date and contains sessions, each with a date and starting and ending time (current code is at https://gitorious.org/django-seminar/). The application is internationalized.

I want to present the date range of an event in a humanized form, using formulations that depend on the particular range at hand, like
  • May 4th, 2012
  • from May 3rd to 5th, 2012 (not sure this is the proper phrasing in English, btw)
  • from April 23rd to May 2nd, 2012
  • from December 27th, 2012 to January 4th, 2013
Obviously, I want this to be translated properly. What would be a proper way to do this?
I came up with two ideas for solving the question, but neither one is fully satisfactory:
  1. use a combination of translatable format strings, like "from %(begin)s to %(end)s" (one for each case) plus one or two translatable strftime format for each case, but that makes for a dozen techincal messages to translate;
  2. use a Python function for formatting, one for each language, stored in a module like locale.en.formats, and use the proper function depending on the context, but that requires some complicated machinery, unless some infrastructure already exists for that.
As a related point, I want to format single dates within this range in a humanized fashion that depends on the context (when presenting a schedule, or in selection lists in forms). For instance, if the date range is from Monday, May 7h to Friday, May 11th, I want to simpy say "Tuesday" or "Tuesday 8th" instead of "May 8th, 2012", since the month and year are known from the context. This, too, combines translation and context dependent formatting.

I am probably not the first one to face this situation. How do people usually cope with this?

--
Emmanuel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wO7QKgUZn1cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment