Django

Code

Ticket #5463 (closed: fixed)

Opened 1 year ago

Last modified 4 months ago

make-messages.py process only .html (not .tpl etc)

Reported by: beer <antiwin@seznam.cz> Assigned to: jezdez
Milestone: 1.0 beta Component: Internationalization
Version: SVN Keywords:
Cc: jshaffer, matthijs@stdin.nl, jannis@leidel.info Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

there should be in settings ie:
I18N_TEMPLATES_EXTENSIONS = ('.html','.tpl')
and default ('.html') for backward compatibility

Attachments

5463.diff (2.6 kB) - added by beer on 09/17/07 16:31:15.
make-messages.1.diff (7.2 kB) - added by jezdez on 06/09/08 07:55:35.
This is a patch that depends on the changes made in patch 6 of ticket #5522 and adds a --extension option to the new djangoadmin.py makemessages tool, as discussed with jacob. ".html" stays the default. fully backwards-compatible and documented.
t5463-r7720.diff (8.9 kB) - added by ramiro on 06/23/08 20:42:20.
t5463-r7844.diff (7.2 kB) - added by jezdez on 07/06/08 08:02:46.
Updated to trunk after merge of #5522, added section to i18n.txt
t5463-r8150.diff (7.1 kB) - added by jezdez on 07/30/08 08:00:28.
Fixed problem as described by Malcolm.
t5463-r8150.2.diff (7.1 kB) - added by jezdez on 07/31/08 11:19:50.
Fixed a bug when using the djangojs domain.

Change History

09/14/07 12:03:32 changed by beer <antiwin@seznam.cz>

  • needs_better_patch changed.
  • component changed from Translations to Internationalization.
  • needs_tests changed.
  • needs_docs changed.

09/14/07 12:14:32 changed by beer

  • keywords set to sprintsept14.

09/14/07 15:37:43 changed by webjunkie

  • stage changed from Unreviewed to Design decision needed.

09/14/07 16:06:15 changed by Fredrik Lundh <fredrik@pythonware.com>

A little nitpicking:

- the imp.load_module stuff looks like overkill; I'd use

try:
    settings_dict = {}
    execfile("settings.py", settings_dict) 
    I18N_TEMPLATE_EXTENSIONS = settings_dict["I18N_TEMPLATE_EXTENSIONS"]
except (IOError, KeyError): 
    I18N_TEMPLATE_EXTENSIONS = settings.I18N_TEMPLATE_EXTENSIONS 

(I have no opinion on whether a check for a local file is a good idea or not)

- Python standard is to include the leading period in extensions; e.g. (".html", ".xml") etc. Not sure what the Django standard is; couldn't find any prior art here. Anyway, if you switch to Python style, you can use "name, ext = os.path.splitext(filename)" to do the split.

09/15/07 00:03:02 changed by mtredinnick

I'm not completely convinced a setting is the right idea here, but we should allow arbitrary extensions or something similar, you're right.

Still needs some design work (meaning "some more thinking"), but it's a good idea.

09/17/07 16:31:15 changed by beer

  • attachment 5463.diff added.

09/17/07 16:37:07 changed by beer

new version: no settings; add some ordinary template extensions as default (html, tpl, xml, txt); add argument -e[list of templates] ie.: -e .asd .zxc

09/18/07 11:14:16 changed by beer

  • has_patch set to 1.
  • stage changed from Design decision needed to Ready for checkin.

09/23/07 03:45:36 changed by ubernostrum

  • stage changed from Ready for checkin to Accepted.

Please don't mark tickets "ready for checkin". Our triagers and core team make that call.

12/19/07 05:23:19 changed by mtredinnick

The default should remain as it is (.html), rather than scanning lots of potentially unneeded files. The rest of the patch is fine.

No need to upload a new patch.. I'll fix it when I check it in.

12/31/07 00:33:27 changed by jshaffer

  • cc set to jshaffer.

04/11/08 04:04:37 changed by Matthijs Kooijman <matthijs@stdin.nl>

  • cc changed from jshaffer to jshaffer, matthijs@stdin.nl.

05/26/08 17:30:06 changed by jezdez

  • cc changed from jshaffer, matthijs@stdin.nl to jshaffer, matthijs@stdin.nl, jannis@leidel.info.

06/08/08 13:44:40 changed by jacob

  • status changed from new to closed.
  • resolution set to duplicate.

#7180 was a duplicate.

06/08/08 13:45:19 changed by jacob

  • status changed from closed to reopened.
  • resolution deleted.

Woops, the other one's a dup, not this one.

06/09/08 07:55:35 changed by jezdez

  • attachment make-messages.1.diff added.

This is a patch that depends on the changes made in patch 6 of ticket #5522 and adds a --extension option to the new djangoadmin.py makemessages tool, as discussed with jacob. ".html" stays the default. fully backwards-compatible and documented.

06/09/08 08:00:01 changed by jezdez

  • owner changed from nobody to jezdez.
  • status changed from reopened to new.

06/09/08 08:00:35 changed by jezdez

  • status changed from new to assigned.

(follow-up: ↓ 18 ) 06/21/08 07:18:36 changed by ramiro

#7520 was a duplicate. One valid point it makes is about the need to also update docs/i18n.txt

(in reply to: ↑ 17 ; follow-up: ↓ 19 ) 06/23/08 13:12:54 changed by jezdez

Replying to ramiro:

#7520 was a duplicate. One valid point it makes is about the need to also update docs/i18n.txt

I don't see any valid point there, there *is* documentation in the latest patch here which needs the changes in #5522.

(in reply to: ↑ 18 ) 06/23/08 20:41:33 changed by ramiro

Replying to jezdez:

I don't see any valid point there, there *is* documentation in the latest patch here which needs the changes in #5522.

I know the patch includes updates to the documentation, but I was specifically talking about i18n.txt. Perhaps adding a note to the Message files section about what file extensions does make-messages.py processes by default and how to change it. Let me know what do you think, I could try to come up with a draft.

Meanwhile, find attached a revised (up to trunk as of r7720) version of the patch because make-messages.1.diff has some problems:

  • make-messages.py: A stray (debug?) print extensions
  • make-messages.py: wrapping/indenting of -a and -e command line switches description is wrong when using -h
  • Usage of mutable sequences as default values of functions parameters
  • Inconsistent usage of organize_extensions/handle_extensions function name (django-admin.py makemessages is currently broken because of this)

06/23/08 20:42:20 changed by ramiro

  • attachment t5463-r7720.diff added.

06/26/08 12:47:23 changed by jezdez

  • milestone set to 1.0 alpha.

06/27/08 09:51:08 changed by garcia_marc

  • keywords deleted.
  • milestone changed from 1.0 alpha to post-1.0.

According to ticket organization defined in http://code.djangoproject.com/wiki/VersionOneRoadmap#how-you-can-help 1.0 alpha tickets should be just features in the Must have (http://code.djangoproject.com/wiki/VersionOneRoadmap#must-have-features) list.

Change to 1.0 beta if you can make this feature be added to May be features (http://code.djangoproject.com/wiki/VersionOneRoadmap#maybe-features).

06/27/08 10:25:41 changed by jezdez

  • milestone changed from post-1.0 to 1.0 beta.

Thanks but this is connected to #5522 and will be in Django 1.0 (as discussed with Jacob in #django-dev).

07/06/08 08:02:46 changed by jezdez

  • attachment t5463-r7844.diff added.

Updated to trunk after merge of #5522, added section to i18n.txt

(follow-up: ↓ 24 ) 07/29/08 23:14:27 changed by mtredinnick

  • needs_better_patch set to 1.

I read through the latest patch. I have a few comments that should probably be looked at before we commit it. Mostly minor things, but there are enough of them that I'm going to bounce it back, rather than tweak them all myself.

  1. Passing in the default value to handle_extensions() doesn't look right. Why not just make the extensions parameter take ('html,) as a default? Basically, there's no reason that default will ever not be '.html', so it shouldn't be a parameter.
  2. Converting the extension to lower-case (line 30) is wrong. Most sensible file systems are case sensitive, so .HTML and .html are different and I'll specify the one I mean on the command line. Most people won't have both, but forcing things to lower-case will cause mismatches in some situations.
  3. Command line parameters can't contain spaces (otherwise there's no way to tell them apart from the next parameter, for example), so you just use .split(',') on line 30. Also, probably prefer some_list.extend(...) over some_list += ...., since it's clearer that you're updating in place and not using some O(n2) copying algorithm.
  4. Line 38 is a real masterpiece of data structure changes: list -> set -> list again, all in one line. :-) You can probably just return a set there, instead of going back to a list. Sets are iterable and that's all you're using it for. This is both a bit shorter and slightly more efficient (you don't go from a set to a list on line 38 and, later one, x in extensions is faster, because "in" for sets is O(1), rather than the O(n) for lists).
  5. Still on line 38, the comparison in the list comprehension is written in a way that looks like it might be a bug (it isn't, but rewrite it to avoid the confusion). Drop the parentheses around the '.py bit, since they're unnecessary. And change not x == '.py' to x != '.py' while you're in there. It's a bit easier to read.
  6. This custom extension stuff really only makes sense for the "django" domain (not "djangojs"), so you might want to make that clear in the documentation. I fear that everybody forgets about poor "djangojs", since "django" is the default domain. But we can probably gamble that all Javascript files end in .js, so you don't have to do anything there (might be worth raising an error is -e is passed in for that case, though).

Once all that is done, I think we're ready to go here.

(in reply to: ↑ 23 ) 07/30/08 07:59:29 changed by jezdez

Replying to mtredinnick:

1. Passing in the default value to handle_extensions() doesn't look right. Why not just make the extensions parameter take ('html,) as a default? Basically, there's no reason that default will ever not be '.html', so it shouldn't be a parameter.

Fixed.

2. Converting the extension to lower-case (line 30) is wrong. Most sensible file systems are case sensitive, so .HTML and .html are different and I'll specify the one I mean on the command line. Most people won't have both, but forcing things to lower-case will cause mismatches in some situations.

Fixed.

3. Command line parameters can't contain spaces (otherwise there's no way to tell them apart from the next parameter, for example), so you just use .split(',') on line 30. Also, probably prefer some_list.extend(...) over some_list += ...., since it's clearer that you're updating in place and not using some O(n2) copying algorithm.

Oh they can contain spaces, by using something like django-admin.py makemessages -e "tpl, html, xml" . I know this is an edge case, but is replace(' ', '') really too expensive at the point? (I left it in the current patch)

4. Line 38 is a real masterpiece of data structure changes: list -> set -> list again, all in one line. :-) You can probably just return a set there, instead of going back to a list. Sets are iterable and that's all you're using it for. This is both a bit shorter and slightly more efficient (you don't go from a set to a list on line 38 and, later one, x in extensions is faster, because "in" for sets is O(1), rather than the O(n) for lists).

Hehe, fixed.

5. Still on line 38, the comparison in the list comprehension is written in a way that looks like it might be a bug (it isn't, but rewrite it to avoid the confusion). Drop the parentheses around the '.py bit, since they're unnecessary. And change not x == '.py' to x != '.py' while you're in there. It's a bit easier to read.

Fixed.

6. This custom extension stuff really only makes sense for the "django" domain (not "djangojs"), so you might want to make that clear in the documentation. I fear that everybody forgets about poor "djangojs", since "django" is the default domain. But we can probably gamble that all Javascript files end in .js, so you don't have to do anything there (might be worth raising an error is -e is passed in for that case, though).

Fixed.

07/30/08 08:00:28 changed by jezdez

  • attachment t5463-r8150.diff added.

Fixed problem as described by Malcolm.

07/31/08 11:19:50 changed by jezdez

  • attachment t5463-r8150.2.diff added.

Fixed a bug when using the djangojs domain.

08/01/08 22:08:04 changed by jshaffer

  • needs_better_patch deleted.

08/08/08 11:41:56 changed by mtredinnick

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

(In [8234]) Fixed #5463 -- Allow alternate file extensions on files that are translated. Patch from Jannis Leidel.


Add/Change #5463 (make-messages.py process only .html (not .tpl etc))




Change Properties
Action