Django

Code

Ticket #7980 (closed: fixed)

Opened 2 years ago

Last modified 2 months ago

I18N needs improvements

Reported by: garcia_marc Assigned to: jezdez
Milestone: 1.2 Component: Internationalization
Version: SVN Keywords: i18n-fixed
Cc: marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com, miracle2k, jacques.beaurain@gmail.com Triage Stage: Fixed on a branch
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

As described in http://vaig.be/2008/07/26/django-i18n-status/ Django's i18n has many features missing.

This ticket is a proposal to:

  • Customize first day of week in admin's calendar (based on current locale).
  • Customize date/datetime formats when a date/datetime is displayed (based on current locale).
  • Customize number format when a decimal number is displayed (based on current locale).
  • Customize input format for date/datetime widgets (based on current locale). It also includes displaying existing data in the same format, when shown on the widget.
  • Customize input format for decimal number widgets (based on current locale). It also includes displaying existing data in the same format, when shown on the widget.

Some other i18n features should be added later, but those are basic for Web site i18n.

Attachments

7980_v1.diff (23.2 kB) - added by garcia_marc on 07/26/08 19:26:29.
Initial patch (partial)
import_cldr.py (2.8 kB) - added by garcia_marc on 08/08/08 19:46:34.
First draft of a script for importing data from CLDR to django
i18n.diff (248.6 kB) - added by garcia_marc on 08/17/09 12:00:45.
diff of all work developed on the [soc2009/i18n]
i18n_simple.diff (79.4 kB) - added by garcia_marc on 08/17/09 12:13:25.
diff of all work developed on the [soc2009/i18n] with .po and formats files removed
i18n-formatting.1.diff (141.9 kB) - added by jezdez on 12/16/09 11:49:17.
Updated patch with relevant parts of i18n GSoC
i18n-formatting.2.diff (142.2 kB) - added by jezdez on 12/16/09 14:55:55.
Fixed issue with LANGUAGE_CODE of sublanguages
i18n-formatting.3.diff (143.8 kB) - added by jezdez on 12/20/09 09:44:55.
Updated format discovery to also look in main locales if not found in sublocales formats
i18n-formatting.4.diff (146.3 kB) - added by jezdez on 12/20/09 09:53:13.
Added Serbian and Serbian latin format strings from #11637
i18n-formatting.5.diff (146.9 kB) - added by jezdez on 12/21/09 14:09:28.
More deprecation warnings and Renamed USE_FORMAT_I18N setting to USE_L10N
i18n-formatting.6.diff (150.3 kB) - added by jezdez on 12/22/09 07:47:00.
Mainly updates to docs

Change History

07/26/08 19:26:29 changed by garcia_marc

  • attachment 7980_v1.diff added.

Initial patch (partial)

07/26/08 19:31:03 changed by garcia_marc

  • needs_better_patch set to 1.
  • needs_tests set to 1.
  • needs_docs set to 1.

V1 patch includes all features except form i18n. Some parts are ugly and need to be coded better, it's just a starting point to see what needs to be changed.

I set milestone to 1.0 beta, because I think it should be included (if finished when 1.0-beta) on 1.0, so it's essential for djangonauts from many countries (most except the US, UK and Australia ;)

07/26/08 19:34:22 changed by Alex

Would it be possible to handle this as individual smaller entities, instead of one monolithic patch.

07/26/08 20:23:42 changed by mtredinnick

  • stage changed from Unreviewed to Accepted.

Yes, we have to do this, but this isn't the right approach, since there's too much manual work. Also, there are tickets already open for most of these things, from memory.

What I want to do here is auto-generate all of this information from the Local Data Markup Language files from the Unicode group. It should be pretty easy to do and then we just drop stuff in the appropriate locale directories. Django can ship a script to parse the file for a new language and we can make that script rely on one download (since it's only needed for maintainers, Django doesn't have to ship it).

I'll leave this open until I hunt out all the dupes later on tonight. I agree we should do this pre-1.0, Marc, but lots more translation stuff like this is probably a burden we can avoid.

08/08/08 19:46:34 changed by garcia_marc

  • attachment import_cldr.py added.

First draft of a script for importing data from CLDR to django

08/08/08 19:48:32 changed by garcia_marc

Attached import_cldr.py isn't finished, and isn't working ok. I just uploaded it for people that is working on improve django's i18n.

08/14/08 01:37:48 changed by mtredinnick

  • milestone changed from 1.0 beta to post-1.0.

This will have to wait until after 1.0. There's still too much work required to get it in before the beta and it requires enough internal changes that it will be potentially destabilising.

I still don't like the first approach in the patch because it adds a lot of settings and makes assumptions such as i18n being enabled. So even it would need some work (and not be backwards compatible with a more general solution). So, sorry, Marc, but this just came a bit late in the process. It's very important, but not worth the risk at the moment.

We'll definitely get it in by 1.1, though.

08/14/08 04:34:57 changed by garcia_marc

I absolutely agree.

Sadly I realized on that when improving and merging the existing patches.

The big news are that it'll be another big fucking party for Django 1.1 if it includes it. ;)

08/19/08 04:46:29 changed by mrts

Imminent duplicated effort alert: http://babel.edgewall.org/ . Can't we just depend on Babel? Also, when things get refactored -- contrib.localflavour should really not be part of Django trunk.

08/19/08 07:45:08 changed by mtredinnick

Please do not post random unrelated comments on tickets (localflavour has nothing to do with this ticket). We aren't duplicating all of Babel, obviously, since we're well aware of that project, and we aren't about to have Django depending on a third-party package the size of Babel. We are incorporating some necessary minimal stuff so that Django's continues to have batteries included.

08/22/08 18:54:33 changed by jacob

#6974 was another duplicate.

10/06/08 22:45:02 changed by anonymous

  • cc changed from marc.garcia@accopensys.com to marc.garcia@accopensys.com, nreilly@nreilly.com.

01/30/09 15:08:15 changed by alexkon

  • cc changed from marc.garcia@accopensys.com, nreilly@nreilly.com to marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com.

02/25/09 13:51:44 changed by

  • milestone deleted.

Milestone post-1.0 deleted

07/23/09 02:59:08 changed by garcia_marc

  • keywords changed from date decimal calendar i18n-rf to i18n-fixed.

Fixed in branches/soc2009/i18n-improvements.

08/10/09 18:50:31 changed by garcia_marc

  • stage changed from Accepted to Fixed on a branch.

08/13/09 05:52:39 changed by marcob

  • cc changed from marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com to marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com.

08/17/09 12:00:45 changed by garcia_marc

  • attachment i18n.diff added.

diff of all work developed on the [soc2009/i18n]

08/17/09 12:13:25 changed by garcia_marc

  • attachment i18n_simple.diff added.

diff of all work developed on the [soc2009/i18n] with .po and formats files removed

(follow-up: ↓ 20 ) 10/20/09 16:26:49 changed by miracle2k

  • cc changed from marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com to marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com, miracle2k.

Not sure what the right place to report this is.

I'm given the soc2009/i18n-improvements branch a try, but have been running into the problem that my German locale is not being used in form submissions. I'm using de_DE as my LANGUAGE_CODE setting, and as far as I was able to tell this is because in django/utils/formats.py, it attempts to import the format file based on django.utils.translation.get_language(), which in my case would return "de-de", when in fact the module to import from is "django.conf.locale.de".

Loading the .mo files doesn't have the same problem, since the gettext loading mechanism seems to auto-fallback to the available "de" locale.

12/08/09 18:02:01 changed by jezdez

  • owner changed from garcia_marc to jezdez.
  • status changed from new to assigned.

(follow-up: ↓ 19 ) 12/15/09 10:18:30 changed by miracle2k

Another bug in that branch: floatformat doesn't correctly print the sign of negative values. Quick-fix here:

http://github.com/miracle2k/django/commit/9259cb9bd1f40167a67714fc037d504c1247d979

(in reply to: ↑ 18 ) 12/15/09 19:04:00 changed by jezdez

  • needs_docs deleted.
  • needs_tests deleted.
  • milestone set to 1.2.

Replying to miracle2k:

Another bug in that branch: floatformat doesn't correctly print the sign of negative values. Quick-fix here: http://github.com/miracle2k/django/commit/9259cb9bd1f40167a67714fc037d504c1247d979

Thanks, I've fixed this in my current working branch: http://github.com/jezdez/django/tree/i18n

(in reply to: ↑ 16 ) 12/15/09 19:06:02 changed by jezdez

Replying to miracle2k:

Not sure what the right place to report this is. I'm given the soc2009/i18n-improvements branch a try, but have been running into the problem that my German locale is not being used in form submissions. I'm using de_DE as my LANGUAGE_CODE setting, and as far as I was able to tell this is because in django/utils/formats.py, it attempts to import the format file based on django.utils.translation.get_language(), which in my case would return "de-de", when in fact the module to import from is "django.conf.locale.de". Loading the .mo files doesn't have the same problem, since the gettext loading mechanism seems to auto-fallback to the available "de" locale.

Good catch, I'll work on a fix for this. It probably involves a simple <locale>[:2] check in case the long format is not found.

12/16/09 11:49:17 changed by jezdez

  • attachment i18n-formatting.1.diff added.

Updated patch with relevant parts of i18n GSoC

12/16/09 14:55:55 changed by jezdez

  • attachment i18n-formatting.2.diff added.

Fixed issue with LANGUAGE_CODE of sublanguages

12/20/09 09:44:55 changed by jezdez

  • attachment i18n-formatting.3.diff added.

Updated format discovery to also look in main locales if not found in sublocales formats

12/20/09 09:53:13 changed by jezdez

  • attachment i18n-formatting.4.diff added.

Added Serbian and Serbian latin format strings from #11637

12/21/09 14:09:28 changed by jezdez

  • attachment i18n-formatting.5.diff added.

More deprecation warnings and Renamed USE_FORMAT_I18N setting to USE_L10N

12/22/09 07:47:00 changed by jezdez

  • attachment i18n-formatting.6.diff added.

Mainly updates to docs

12/22/09 11:58:50 changed by jezdez

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [11964]) Fixed #7980 - Improved i18n framework to support locale aware formatting (dates and numbers) and form processing.

Thanks to Marc Garcia for working on this during his Google Summer of Code 2009!

Additionally fixes #1061, #2203, #3940, #5526, #6449, #6231, #6693, #6783, #9366 and #10891.

01/08/10 12:18:45 changed by Jacques Beaurain <jacques.beaurain@gmail.com>

  • cc changed from marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com, miracle2k to marc.garcia@accopensys.com, nreilly@nreilly.com, alexkon@gmail.com, marcoberi@gmail.com, miracle2k, jacques.beaurain@gmail.com.
  • status changed from closed to reopened.
  • resolution deleted.

I just created ticket #12550 with a patch for a bug caused by the changes comitted for this one. Since my patch only deals with DecimalField? and this is a large submission I am not sure if there might be other types affected. I think it might be good for someone with more knowledge of the django.contrib.admin codebase to review this.

01/08/10 12:36:29 changed by ramiro

  • status changed from reopened to closed.
  • resolution set to fixed.

This ticket was closed because the original fature has been implemented.

If you opened another ticket, there is no need to reopen this one. Doing so isn't the right way to bring attention to the issue.

01/08/10 12:44:00 changed by kmtracey

As Ramiro said, we only need one ticket to track the follow-on bug, and the right ticket for that is the new one, not this one. Concerns about there possibly being other field types affected should be noted there. Tests covering all field types would be a way to find out if the problem affects other field types. A test needs to be developed anyway for the DecimalField case; it should not be hard to expand that test to also test other field types. That would be useful both to find out whether the problem affects other fields, and to put in the test suite in either case to ensure this kind of problem, for any field type, does not recur with any future code changes.

01/08/10 13:11:24 changed by Jacques Beaurain <jacques.beaurain@gmail.com>

Sorry about that, my aim was not really to try and draw attention to that ticket, I already added tests and fixed it so that it does not happen for other field types.

I added notes here more to notify whoever was involved in this one that there might be other places (not related to admin list display necessarily) that was affected by this change and for anybody in the know to review the patch for this again.


Add/Change #7980 (I18N needs improvements)




Change Properties
Action