Opened 18 years ago

Last modified 12 years ago

#4147 new New feature

Add some i18n hooks to DateFormat

Reported by: orestis Owned by: Marc Garcia
Component: Internationalization Version: dev
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 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by orestis@…, 18 years ago

Cc: orestis@… added

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

comment:3 by Malcolm Tredinnick, 18 years ago

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 by orestis@…, 18 years ago

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 by orestis@…, 17 years ago

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 by Antti Kaihola, 17 years ago

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 by orestis@…, 17 years ago

akaihola:

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

in reply to:  7 ; comment:8 by Antti Kaihola, 17 years ago

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"?

in reply to:  8 comment:9 by anonymous, 17 years ago

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 by orestis@…, 17 years ago

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 by orestis@…, 17 years ago

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 by zgollum, 17 years ago

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

comment:13 by orestis@…, 17 years ago

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 by tonnzor <tonn81@…>, 17 years ago

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 by anonymous, 17 years ago

Cc: ctrochalakis added

comment:16 by Marc Garcia, 16 years ago

Keywords: i18n-rf added
milestone: post-1.0

comment:17 by Alexander Konovalenko, 16 years ago

Cc: alexkon@… added

comment:18 by Jari Pennanen, 16 years ago

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

comment:19 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:20 by Marc Garcia, 15 years ago

Keywords: i18n-rf removed

comment:21 by Marc Garcia, 15 years ago

Owner: changed from nobody to Marc Garcia

comment:22 by marcob, 15 years ago

Cc: marcoberi@… added

comment:23 by shell_dweller, 15 years ago

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 by orestis, 15 years ago

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 by Malcolm Tredinnick, 14 years ago

Triage Stage: Design decision neededAccepted

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 by anonymous, 14 years ago

Cc: s.kuzmenko@… added

comment:27 by Łukasz Rekucki, 14 years ago

Severity: Normal
Type: New feature

comment:28 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:29 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:30 by ciprianmp@…, 12 years ago

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 by anonymous, 12 years ago

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