Opened 8 years ago

Last modified 2 years ago

#4147 new New feature

Add some i18n hooks to DateFormat

Reported by: orestis Owned by: garcia_marc
Component: Internationalization Version: master
Severity: Normal Keywords: dates month
Cc: orestis@…, ctrochalakis, alexkon@…, marcoberi@…, s.kuzmenko@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django's handling of i18n is fairly good, but one major point that it doesn't handle well (together with almost everything else out there) is the formatting of dates.

The most obvious example is the display of the month names. While in English there is only one case of nouns, in many other european languages there are more, which have different spellings.
For example, in Greek, in order to be able to diplay full-word months and capture all possible sentence formats, one needs three cases:

  1. The subjective case (eg. en: January, 2007 - el: Ιανουάριος, 2007)
  2. The posessive case (eg. en: 23th of January - el: 23η Ιανουαρίου)
  3. The objective case (eg. en: Entries posted on January - el: Δημοσιεύσεις που έγιναν τον Ιανουάριο)

I'm sure this is common in most european languages, but I'm not an expert; Please everybody comment on this.

To implement this in django, I suggest the following:

  • Add MONTHS_POS, MONTHS_OBJ to django.utils.dates. This should read "of January" and "on January" in english .
  • Add a custom extension in django.utils.dateformat: Q for MONTHS_POS, V for MONTHS_OBJ. Any available letter should do.

That's all. There is a=still an issue about the format 'S' that adds the ordinals (1st, 2nd etc) but I don't know how other languages deal with this.

I can submit a patch for this...

Change History (31)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by orestis@…

  • Cc orestis@… added

should I provide a patch for this? I don't think it'd be hard. I just need confirmation.

comment:3 Changed 8 years ago by mtredinnick

I haven't thought about this enough to really know if this is the right approach or not. Please have some patience, you are only one of many people requesting things be added to the code and you only opened the ticket 24 hours ago.

Write a patch if you want, it can't hurt. However, I'm trying to think of some way to do this that maybe doesn't involve creating a bunch of new settings and format modifiers. It is very important that we also keep things easy to write the code in the first place. Might be worth having a discussion on django-i18n first before writing this. Tickets aren't the best place to have a discussion about a feature.

comment:4 Changed 8 years ago by orestis@…

The discussion is available here: http://groups.google.com/group/Django-I18N/browse_thread/thread/3f5dfb2a9a10f904

I have posted some more thoughts on how this could be implemented.

comment:5 Changed 8 years ago by orestis@…

I've created a contrib app that handles this. It is available from here:

http://code.google.com/p/django-localdates

It is described here:

http://orestis.gr/en/blog/2007/07/17/django-localdates/

comment:6 Changed 8 years ago by akaihola

The corresponding cases in Finnish are:

  1. The subjective case (eg. en: January, 2007 - fi: tammikuu 2007)
  2. The possessive case (eg. en: 23th of January - fi: 23. tammikuuta)
  3. The objective case (eg. en: Entries posted in January - fi: tammikuussa kirjoitetut viestit)

In addition, case 2. could be expressed as "tammikuun 23. päivänä" (literally "on the 23rd day of January), especially in prose (as opposed to labels).

comment:7 follow-up: Changed 8 years ago by orestis@…

akaihola:

could you express these cases in the format specified by django-localdates? See above for source. If you have issues contact me.

comment:8 in reply to: ↑ 7 ; follow-up: Changed 8 years ago by akaihola

Replying to orestis@orestis.gr:

could you express these cases in the format specified by django-localdates? See above for source. If you have issues contact me.

Just hacking your source code to add support for Finnish. Do I understand correctly that you use LocalDateFormat.Fd() and local_dates.MONTHS_DIR for the case corresponding to the phrase "in January"?

comment:9 in reply to: ↑ 8 Changed 8 years ago by anonymous

Replying to akaihola:

Replying to orestis@orestis.gr:

could you express these cases in the format specified by django-localdates? See above for source. If you have issues contact me.

Just hacking your source code to add support for Finnish. Do I understand correctly that you use LocalDateFormat.Fd() and local_dates.MONTHS_DIR for the case corresponding to the phrase "in January"?

It is a little more complicated than that - please email me so we can stop spamming the ticket comments.

comment:10 Changed 8 years ago by orestis@…

I've updated the application so translators can add new functionality without writing any code - just use the regular django translation mechanisms. I've also added a sample project that demonstrates the usage of the template.

Check it out here: http://code.google.com/p/django-localdates

comment:11 Changed 8 years ago by orestis@…

Courtesy of akaihola, there is now support for Finnish.

After a refactoring, adding translations is as simple as editing a django.po file, so please come in and add them!

comment:12 Changed 8 years ago by zgollum

I attached a Russian version there. http://code.google.com/p/django-localdates

comment:13 Changed 7 years ago by orestis@…

After some very helpful comments from akaihola, I've made some nice changes to the code. It should now work for most, if not all, cases.

Please give it a look and add more translations.

comment:14 Changed 7 years ago by tonnzor <tonn81@…>

I used the code and it's useful and fine. It would be great if it is included in Django by default so no additional code and special template tag is used.

comment:15 Changed 7 years ago by anonymous

  • Cc ctrochalakis added

comment:16 Changed 7 years ago by garcia_marc

  • Keywords i18n-rf added
  • milestone set to post-1.0

comment:17 Changed 7 years ago by alexkon

  • Cc alexkon@… added

comment:18 Changed 7 years ago by Ciantic

I provided patch long time ago, see http://code.djangoproject.com/ticket/4121 it worked just fine back then, none cared though.

comment:19 Changed 7 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:20 Changed 6 years ago by garcia_marc

  • Keywords i18n-rf removed

comment:21 Changed 6 years ago by garcia_marc

  • Owner changed from nobody to garcia_marc

comment:22 Changed 6 years ago by marcob

  • Cc marcoberi@… added

comment:23 Changed 6 years ago by shell_dweller

I think a better way would be to use Babel which also has a Django implementation (http://babel.edgewall.org/wiki/BabelDjango). It uses the Unicode CLDR which provides standard date representations. Specifically it makes use of "wide" representations which for Greek are equivalents of possessive case:

>>> import babel
>>> from babel.dates import format_date
>>> from datetime import date
>>> now = date.today()
>>> print format_date(now, format='d MMMM yyyy', locale='el')
21 Δεκεμβρίου 2009
>>> print format_date(now, format='long', locale='el')
21 Δεκεμβρίου 2009

What UCLDR cannot be used for is interpolations like "from %s to %s" % (month1, month2). This is however in general case is a non trivial problem which belongs rather to the domain of computational linguistics then to internationalization.

comment:24 Changed 6 years ago by orestis

shell_dweller:

Thanks - When I created django-localdates, Babel didn't have any django integration or template tags. It looks like it's a better, more complete and of course more maintained solution.

comment:25 Changed 5 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

We accept that this is a requirement if it's possible. Not clear that it is fully possible, across the wide range of human language forms and their syntactic requirements, but let's work on it a bit (Greek isn't the most technically tricky language of the lot out there, by any means).

comment:26 Changed 5 years ago by anonymous

  • Cc s.kuzmenko@… added

comment:27 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:28 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:29 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:30 Changed 2 years ago by ciprianmp@…

I'm implementing the local possessive/genitive support for month names in a calendar class, for languages that require this transformation.
I have followed the entire conversation here as well as all the links provided, but also looked it up a lot on google for the list of month names in the specific format. I couldn't find anywhere a list of Serbian month names in genitive case, except this general rule: http://www.lztranslation.com/pdf/serbian-genitive-case.pdf

I would kindly ask native people of these specific countries that request support for their own language, to provide a list of the correct spelling of each month in their case (both Latin and Cyrillic if the case). That will help a lot.

Also a comprehensive list the languages that require this modification would be awesome. I could only find lists like "maybe that language or that language too". That's just confusing developers and people that like the professional implementation of globalization standards. (I'm not surprized not even MS or other huge corporations don't provide such lists on MSDN, just examples of one word per language...)

Thank you.

comment:31 Changed 2 years ago by anonymous

I think this was fixed in 14570 with introduction of "locale specific alternative month representation", see https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#date

You probably just need to update your Serbian translation to get genitive support in dates.

Note: See TracTickets for help on using tickets.
Back to Top