Ticket #15495: ticket15495.diff
File ticket15495.diff, 7.2 KB (added by , 14 years ago) |
---|
-
django/core/management/commands/makemessages.py
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index a244a60..48d761a 100644
a b from subprocess import PIPE, Popen 10 10 from django.core.management.base import CommandError, NoArgsCommand 11 11 from django.utils.text import get_text_list 12 12 13 pythonize_re = re.compile(r'(?:^|\n)\s*//')14 13 plural_forms_re = re.compile(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', re.MULTILINE | re.DOTALL) 15 14 15 # this removes everything after comment, so the next regexp 16 # doesn't messup anything 17 jspythonize_re = re.compile(r'(?:^|\n)\s*//.*') 18 jsblockcomments_re = re.compile(r'/\*(.+?)\*/', re.DOTALL) 19 20 def pythonizejs(text): 21 def block_comment_replacement(m): 22 nlcount = m.group(1).count('\n') 23 if not nlcount: 24 return "" 25 return '\n'.join("#" * (nlcount + 1)) 26 text = jspythonize_re.sub('\n#', text) 27 text = jsblockcomments_re.sub(block_comment_replacement, text) 28 return text 29 16 30 def handle_extensions(extensions=('html',)): 17 31 """ 18 32 organizes multiple extensions that are separated with commas or passed by … … def make_messages(locale=None, domain='django', verbosity='1', all=False, 184 198 if verbosity > 1: 185 199 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 186 200 src = open(os.path.join(dirpath, file), "rU").read() 187 src = pythonize _re.sub('\n#',src)201 src = pythonizejs(src) 188 202 thefile = '%s.py' % file 189 203 f = open(os.path.join(dirpath, thefile), "w") 190 204 try: -
tests/regressiontests/i18n/commands/extraction.py
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index f17bb47..46a816d 100644
a b class ExtractorTests(TestCase): 27 27 pass 28 28 os.chdir(self._cwd) 29 29 30 def assertMsgId(self, msgid, s, use_quotes=True):30 def assertMsgId(self, msgid, text, use_quotes=True): 31 31 if use_quotes: 32 32 msgid = '"%s"' % msgid 33 return self.assert_(re.search('^msgid %s' % msgid, s, re.MULTILINE))33 self.assertRegexpMatches(text, '(?m)^msgid %s' % re.escape(msgid)) 34 34 35 def assert NotMsgId(self, msgid, s, use_quotes=True):35 def assertMsgIdLineNumber(self, msgid, linenumber, text, use_quotes=True): 36 36 if use_quotes: 37 37 msgid = '"%s"' % msgid 38 return self.assert_(not re.search('^msgid %s' % msgid, s, re.MULTILINE)) 38 m = re.search('^#: .+:(\d+)\n^msgid %s' % re.escape(msgid), text, re.M) 39 self.assertIsNotNone(m) 40 self.assertEqual(int(m.group(1)), linenumber) 41 42 def assertNotMsgId(self, msgid, text, use_quotes=True): 43 if use_quotes: 44 msgid = '"%s"' % msgid 45 self.assertNotRegexpMatches(text, '(?m)^msgid %s' % re.escape(msgid)) 39 46 40 47 41 48 class BasicExtractorTests(ExtractorTests): … … class BasicExtractorTests(ExtractorTests): 57 64 self.assert_(os.path.exists(self.PO_FILE)) 58 65 po_contents = open(self.PO_FILE, 'r').read() 59 66 self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents) 60 self.assertMsgId('I think that 100%% is more that 50%% of % \(obj\)s.', po_contents)67 self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents) 61 68 62 69 def test_extraction_error(self): 63 70 os.chdir(self.test_dir) … … class JavascriptExtractorTests(ExtractorTests): 79 86 80 87 def test_javascript_literals(self): 81 88 os.chdir(self.test_dir) 82 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 83 self.assert_(os.path.exists(self.PO_FILE)) 84 po_contents = open(self.PO_FILE, 'r').read() 85 self.assertMsgId('This literal should be included.', po_contents) 86 self.assertMsgId('This one as well.', po_contents) 89 shutil.copyfile('./javascript/literals.txt', './javascript.js') 90 try: 91 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 92 self.assert_(os.path.exists(self.PO_FILE)) 93 po_contents = open(self.PO_FILE, 'r').read() 94 self.assertMsgId('This literal should be included.', po_contents) 95 self.assertMsgId('This one as well.', po_contents) 96 self.assertMsgId('This too', po_contents) 97 self.assertNotMsgId('Ignore', po_contents) 98 finally: 99 os.remove('./javascript.js') 87 100 101 def test_javascript_block_comments(self): 102 os.chdir(self.test_dir) 103 shutil.copyfile('./javascript/block_comments.txt', './javascript.js') 104 try: 105 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 106 self.assert_(os.path.exists(self.PO_FILE)) 107 po_contents = open(self.PO_FILE, 'r').read() 108 self.assertMsgId('Line1', po_contents) 109 self.assertMsgId('Line6A', po_contents) 110 self.assertMsgId('Line6B', po_contents) 111 self.assertMsgId('Line8', po_contents) 112 self.assertMsgId('Line12', po_contents) 113 self.assertNotMsgId('Ignore', po_contents) 114 # check line number 115 self.assertMsgIdLineNumber('Line1', 1, po_contents) 116 self.assertMsgIdLineNumber('Line6A', 6, po_contents) 117 self.assertMsgIdLineNumber('Line6B', 6, po_contents) 118 self.assertMsgIdLineNumber('Line8', 8, po_contents) 119 self.assertMsgIdLineNumber('Line12', 12, po_contents) 120 finally: 121 os.remove('./javascript.js') 88 122 89 123 class IgnoredExtractorTests(ExtractorTests): 90 124 -
deleted file tests/regressiontests/i18n/commands/javascript.js
diff --git a/tests/regressiontests/i18n/commands/javascript.js b/tests/regressiontests/i18n/commands/javascript.js deleted file mode 100644 index bc5ec87..0000000
+ - 1 // '2 gettext('This literal should be included.')3 // '4 gettext('This one as well.') -
new file tests/regressiontests/i18n/commands/javascript/block_comments.txt
diff --git a/tests/regressiontests/i18n/commands/javascript/block_comments.txt b/tests/regressiontests/i18n/commands/javascript/block_comments.txt new file mode 100644 index 0000000..843e840
- + 1 /* / ' */ gettext("Line1"); 2 function() { 3 /* 4 * Some long comment/message that doesn't do anything 5 */ 6 gettext("Line6A"); /* */ gettext("Line6B"); 7 /* one line comment */ 8 gettext("Line8"); 9 /* 10 * Another comment with magic sequence / ' 11 */ 12 gettext("Line12"); 13 /* gettext("Ignore") */ 14 } 15 No newline at end of file -
new file tests/regressiontests/i18n/commands/javascript/literals.txt
diff --git a/tests/regressiontests/i18n/commands/javascript/literals.txt b/tests/regressiontests/i18n/commands/javascript/literals.txt new file mode 100644 index 0000000..362d34c
- + 1 // ' 2 gettext('This literal should be included.') 3 // ' 4 gettext('This one as well.') 5 // /* fake comment start 6 gettext('This too') 7 // fake end */ gettext('Ignore') 8 No newline at end of file