Django

Code

Ticket #7084 (closed: fixed)

Opened 7 months ago

Last modified 3 months ago

django-admin.py makemessages fails on multiline blocktrans tags on Windows

Reported by: MihaiD Assigned to: nobody
Milestone: 1.0 Component: Internationalization
Version: SVN Keywords: make-messages xgettext new line \r makemessages
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

Running make-messages.py on the Django SVN version on Windows produces the following error:

errors happened while running xgettext on bookmarklets.html
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence
xgettext: internationalized messages should not contain the `\r' escape sequence

The error is caused by \r\n line terminators in Windows that get passed to xgettext. As make-messages.py calls django.utils.translation.templatize to produce the input files for xgettext, maybe the os.name could be checked there and have the \r stripped.

Attachments

trans_real.py (2.0 kB) - added by MihaiD on 04/25/08 06:51:03.
patch for django.utils.translation.templatize
t7084.diff (1.9 kB) - added by ramiro on 05/03/08 12:05:41.
My try at fixing this problem. Tested with the Django catalogs under WIndows and Linux.
t7084_post_r7844.diff (1.9 kB) - added by ramiro on 07/22/08 13:43:50.
t7084-r8255.diff (2.0 kB) - added by ramiro on 08/09/08 11:56:29.
t7084-r8534.diff (2.9 kB) - added by ramiro on 08/25/08 07:25:19.
New version of patch, makemessages always creates/update .po files with Unix line-endings, even on Windows

Change History

04/25/08 06:51:03 changed by MihaiD

  • attachment trans_real.py added.

patch for django.utils.translation.templatize

04/25/08 06:52:40 changed by MihaiD

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

Added possible patch for the templatize function. Checked it on Windows and it worked.

05/03/08 12:05:41 changed by ramiro

  • attachment t7084.diff added.

My try at fixing this problem. Tested with the Django catalogs under WIndows and Linux.

06/14/08 09:14:49 changed by telenieko

  • stage changed from Unreviewed to Accepted.

07/22/08 12:30:23 changed by mir

  • milestone set to 1.0 beta.

This should work for Windows beta testers, so I set the mile stone to 1.0beta.

07/22/08 13:43:50 changed by ramiro

  • attachment t7084_post_r7844.diff added.

07/22/08 13:50:15 changed by ramiro

Had forgot about this one. I've attached a patch updating the approach I propose to trunk post-r7844.

You might also want to apply this minimal additional modification to the same file (didn't want to include this in the patch because it's strictly unrelated):

diff -r 1b29e4bb845e django/core/management/commands/makemessages.py
--- a/django/core/management/commands/makemessages.py   Tue Jul 22 15:40:25 2008 -0300
+++ b/django/core/management/commands/makemessages.py   Tue Jul 22 15:48:06 2008 -0300
@@ -68,8 +68,8 @@
                     sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
                 src = open(os.path.join(dirpath, file), "rU").read()
                 src = pythonize_re.sub('\n#', src)
-                open(os.path.join(dirpath, '%s.py' % file), "wt").write(src)
                 thefile = '%s.py' % file
+                open(os.path.join(dirpath, thefile), "wt").write(src)
                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
                 (stdin, stdout, stderr) = os.popen3(cmd, 't')
                 msgs = stdout.read()

(follow-up: ↓ 6 ) 08/08/08 18:07:01 changed by mtredinnick

  • needs_better_patch set to 1.
  • needs_tests deleted.

There's not documented "t" option to open(), so what are you trying to do there?

(in reply to: ↑ 5 ) 08/09/08 11:52:43 changed by ramiro

Replying to mtredinnick:

There's not documented "t" option to open(), so what are you trying to do there?

My bad, I don't know where I the got the 't's, what I was trying to do was just eliminate 'b'. I'm attaching a corrected version of the patch updated to r8255. It doesn't break things under Linux and corrects multi-line msgid extraction under Windows, in both cases generating the full set of Django django.po catalogs.

08/09/08 11:56:29 changed by ramiro

  • attachment t7084-r8255.diff added.

(follow-up: ↓ 9 ) 08/09/08 12:09:59 changed by mtredinnick

Ramiro: now I have another question... Aren't those write changes going to affect things as the files move between Windows and linux, say? Since you're now writing out with native line-endings, rather than the same line ending in every case (as I understand the change), won't this mean that a PO file generated on Linux and then updated on Windows will come back with a patch that changes every line ending? That would be bad.

It's possible I'm not understanding the effect there, but we do have a number of locale files that are translated by people using Windows, Linux and Mac systems and I don't want a run of patches that only mess around with line endings (which I thought we just fixed last year). You're the guy with the experience here, so I'll trust your conclusions, but can you confirm you haven't made things less portable in this fashion.

08/09/08 12:31:18 changed by mtredinnick

  • milestone changed from 1.0 beta to 1.0.

Moving to the 1.0 milestone. We should definitely fix this as soon as we can; it's a real bug. But it's not something that will disrupt things so much that it absolutely must be in beta.

08/25/08 07:25:19 changed by ramiro

  • attachment t7084-r8534.diff added.

New version of patch, makemessages always creates/update .po files with Unix line-endings, even on Windows

(in reply to: ↑ 7 ) 08/25/08 07:42:55 changed by ramiro

Replying to mtredinnick:

Ramiro: now I have another question... Aren't those write changes going to affect things as the files move between Windows and linux, say? Since you're now writing out with native line-endings, rather than the same line ending in every case (as I understand the change), won't this mean that a PO file generated on Linux and then updated on Windows will come back with a patch that changes every line ending? That would be bad.

That is exactly what was happening, thanks for noting it. I've modified things even further so makemessages command always creates the .po catalogs with Unix file-endings. See attached patch.

I´ve tested it under Linux and Windows both creating django and djangojs .po files from scratch and updating existing ones.

While loking at this I found the script doesn´t cleanup after istelf when it finds an error executing the gettext tools. I've opened a ticket for that (#8536).

One minor (not critical at all) note: In a .po file created or updated under Windows, location comments located above every msgid will have the form

#: .\conf\global_settings.py:44
msgid "Arabic"
...

instead of

#: conf/global_settings.py:44
msgid "Arabic"
...

08/25/08 09:02:27 changed by ramiro

  • keywords changed from make-messages xgettext new line \r to make-messages xgettext new line \r makemessages.
  • summary changed from make-messages fails on multiline blocktrans tags on Windows to django-admin.py makemessages fails on multiline blocktrans tags on Windows.

08/26/08 02:44:55 changed by mtredinnick

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

Fixed in [8576].


Add/Change #7084 (django-admin.py makemessages fails on multiline blocktrans tags on Windows)




Change Properties
Action