Ticket #7704: makemessages.diff
File makemessages.diff, 5.0 KB (added by , 14 years ago) |
---|
-
django/core/management/commands/makemessages.py
9 9 10 10 from django.core.management.base import CommandError, NoArgsCommand 11 11 from django.utils.text import get_text_list 12 from django.utils.jslex import js_to_c_for_gettext 12 13 13 pythonize_re = re.compile(r'(?:^|\n)\s*//')14 14 plural_forms_re = re.compile(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', re.MULTILINE | re.DOTALL) 15 15 16 16 def handle_extensions(extensions=('html',)): … … 184 184 if verbosity > 1: 185 185 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 186 186 src = open(os.path.join(dirpath, file), "rU").read() 187 src = pythonize_re.sub('\n#',src)188 thefile = '%s. py' % file187 src = js_to_c_for_gettext(src) 188 thefile = '%s.c' % file 189 189 f = open(os.path.join(dirpath, thefile), "w") 190 190 try: 191 191 f.write(src) 192 192 finally: 193 193 f.close() 194 194 cmd = ( 195 'xgettext -d %s -L Perl%s --keyword=gettext_noop '195 'xgettext -d %s -L C %s --keyword=gettext_noop ' 196 196 '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 ' 197 197 '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 ' 198 198 '--from-code UTF-8 --add-comments=Translators -o - "%s"' % ( -
tests/regressiontests/i18n/commands/javascript.js
1 1 // ' 2 2 gettext('This literal should be included.') 3 // ' 4 gettext('This one as well.') 3 x = y; // ' 4 gettext("This one as well.") 5 6 /** (from ticket 7704) 7 * ***************************** 8 * AddModule main / window 9 * @constructor 10 * @class MyDesktop.AddModule 11 * ***************************** 12 */ 13 14 gettext('He said, \"hello".') 15 16 // from ticket 14045 17 function mfunc() { 18 var val = 0; 19 return val ? 1 : 0; 20 } 21 gettext('okkkk'); 22 print mysub(); 23 24 // from ticket 15495 25 /* / ' */ gettext("TEXT"); 26 27 gettext("It's at http://example.com") 28 29 // also from ticket 15495 30 gettext("String"); // This comment won't be caught by pythonize_re and it contains "'" which is a string start in Perl 31 /* 32 * This one will be removed by the patch 33 */ 34 gettext("/* but this one will be too */ 'cause there is no way of telling..."); 35 f(/* ... if it's different from this one */); 36 37 // from ticket 15331 38 gettext("foo"); 39 true ? true : false; 40 gettext("bar"); 41 true ? true : false; 42 gettext("baz"); 43 true ? true : false; // ? 44 gettext("quz"); 45 "?"; 46 gettext("foobar"); 47 -
tests/regressiontests/i18n/commands/extraction.py
30 30 def assertMsgId(self, msgid, s, use_quotes=True): 31 31 if use_quotes: 32 32 msgid = '"%s"' % msgid 33 msgid = re.escape(msgid) 33 34 return self.assertTrue(re.search('^msgid %s' % msgid, s, re.MULTILINE)) 34 35 35 36 def assertNotMsgId(self, msgid, s, use_quotes=True): 36 37 if use_quotes: 37 38 msgid = '"%s"' % msgid 39 msgid = re.escape(msgid) 38 40 return self.assertTrue(not re.search('^msgid %s' % msgid, s, re.MULTILINE)) 39 41 40 42 … … 69 71 self.assertTrue(os.path.exists(self.PO_FILE)) 70 72 po_contents = open(self.PO_FILE, 'r').read() 71 73 self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents) 72 self.assertMsgId('I think that 100%% is more that 50%% of % \(obj\)s.', po_contents)74 self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents) 73 75 74 76 def test_extraction_error(self): 75 77 os.chdir(self.test_dir) … … 95 97 po_contents = open(self.PO_FILE, 'r').read() 96 98 self.assertMsgId('This literal should be included.', po_contents) 97 99 self.assertMsgId('This one as well.', po_contents) 100 self.assertMsgId(r'He said, \"hello\".', po_contents) 101 self.assertMsgId("okkkk", po_contents) 102 self.assertMsgId("TEXT", po_contents) 103 self.assertMsgId("It's at http://example.com", po_contents) 104 self.assertMsgId("String", po_contents) 105 self.assertMsgId("/* but this one will be too */ 'cause there is no way of telling...", po_contents) 106 self.assertMsgId("foo", po_contents) 107 self.assertMsgId("bar", po_contents) 108 self.assertMsgId("baz", po_contents) 109 self.assertMsgId("quz", po_contents) 110 self.assertMsgId("foobar", po_contents) 98 111 99 100 112 class IgnoredExtractorTests(ExtractorTests): 101 113 102 114 def test_ignore_option(self):