Ticket #10004: comment-extraction.patch
File comment-extraction.patch, 7.3 KB (added by , 14 years ago) |
---|
-
django/core/management/commands/makemessages.py
196 196 'xgettext -d %s -L Perl %s --keyword=gettext_noop ' 197 197 '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 ' 198 198 '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 ' 199 '--from-code UTF-8 - o - "%s"' % (199 '--from-code UTF-8 --add-comments=L10n -o - "%s"' % ( 200 200 domain, wrap, os.path.join(dirpath, thefile) 201 201 ) 202 202 ) … … 240 240 '--keyword=ugettext_noop --keyword=ugettext_lazy ' 241 241 '--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 ' 242 242 '--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 ' 243 '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 -o - ' 244 '"%s"' % (domain, wrap, os.path.join(dirpath, thefile)) 243 '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 ' 244 '--add-comments=L10n -o - "%s"' % ( 245 domain, wrap, os.path.join(dirpath, thefile)) 245 246 ) 246 247 msgs, errors = _popen(cmd) 247 248 if errors: -
tests/regressiontests/i18n/commands/__init__.py
1 from django.utils.translation import ugettext as _ 2 3 # L10n: This comment should be extracted 4 dummy1 = _("This is a translatable string.") 5 6 # This comment should not be extracted 7 dummy2 = _("This is another translatable string.") 8 -
tests/regressiontests/i18n/commands/extraction.py
8 8 9 9 class ExtractorTests(TestCase): 10 10 11 PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE 11 PO_FILE ='locale/%s/LC_MESSAGES/django.po' % LOCALE 12 JS_PO_FILE ='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE 12 13 13 14 def setUp(self): 14 15 self._cwd = os.getcwd() … … 38 39 return self.assert_(not re.search('^msgid %s' % msgid, s, re.MULTILINE)) 39 40 40 41 41 class TemplateExtractorTests(ExtractorTests):42 class BasicExtractorTests(ExtractorTests): 42 43 43 def test_templatize(self): 44 def setUp(self): 45 super(BasicExtractorTests, self).setUp() 44 46 os.chdir(self.test_dir) 47 48 def test_templatize(self): 45 49 management.call_command('makemessages', locale=LOCALE, verbosity=0) 46 50 self.assert_(os.path.exists(self.PO_FILE)) 47 51 po_contents = open(self.PO_FILE, 'r').read() 48 52 self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents) 49 53 self.assertMsgId('I think that 100%% is more that 50%% of %\(obj\)s.', po_contents) 50 54 55 def test_copy_plural_forms(self): 56 management.call_command('makemessages', locale=LOCALE, verbosity=0) 57 self.assert_(os.path.exists(self.PO_FILE)) 58 po_contents = open(self.PO_FILE, 'r').read() 59 self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents) 51 60 52 class JavascriptExtractorTests(ExtractorTests): 61 def test_comments_extractor(self): 62 management.call_command('makemessages', locale=LOCALE, verbosity=0) 63 self.assert_(os.path.exists(self.PO_FILE)) 64 po_contents = open(self.PO_FILE, 'r').read() 65 self.assert_('#. L10n: This comment should be extracted' in po_contents) 66 self.assert_('This comment should not be extracted' not in po_contents) 53 67 54 PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE55 56 68 def test_javascript_literals(self): 57 os.chdir(self.test_dir)58 69 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 59 self.assert_(os.path.exists(self. PO_FILE))60 po_contents = open(self. PO_FILE, 'r').read()70 self.assert_(os.path.exists(self.JS_PO_FILE)) 71 po_contents = open(self.JS_PO_FILE, 'r').read() 61 72 self.assertMsgId('This literal should be included.', po_contents) 62 73 self.assertMsgId('This one as well.', po_contents) 63 74 64 65 class IgnoredExtractorTests(ExtractorTests):66 67 75 def test_ignore_option(self): 68 os.chdir(self.test_dir)69 76 management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*']) 70 77 self.assert_(os.path.exists(self.PO_FILE)) 71 78 po_contents = open(self.PO_FILE, 'r').read() 72 79 self.assertMsgId('This literal should be included.', po_contents) 73 80 self.assertNotMsgId('This should be ignored.', po_contents) 74 81 82 def test_no_wrap_enabled(self): 83 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True) 84 self.assert_(os.path.exists(self.PO_FILE)) 85 po_contents = open(self.PO_FILE, 'r').read() 86 self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents) 75 87 88 def test_no_wrap_disabled(self): 89 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False) 90 self.assert_(os.path.exists(self.PO_FILE)) 91 po_contents = open(self.PO_FILE, 'r').read() 92 self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False) 93 94 76 95 class SymlinkExtractorTests(ExtractorTests): 77 96 78 97 def setUp(self): … … 101 120 po_contents = open(self.PO_FILE, 'r').read() 102 121 self.assertMsgId('This literal should be included.', po_contents) 103 122 self.assert_('templates_symlinked/test.html' in po_contents) 104 105 106 class CopyPluralFormsExtractorTests(ExtractorTests):107 108 def test_copy_plural_forms(self):109 os.chdir(self.test_dir)110 management.call_command('makemessages', locale=LOCALE, verbosity=0)111 self.assert_(os.path.exists(self.PO_FILE))112 po_contents = open(self.PO_FILE, 'r').read()113 self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)114 115 116 class NoWrapExtractorTests(ExtractorTests):117 118 def test_no_wrap_enabled(self):119 os.chdir(self.test_dir)120 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)121 self.assert_(os.path.exists(self.PO_FILE))122 po_contents = open(self.PO_FILE, 'r').read()123 self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents)124 125 def test_no_wrap_disabled(self):126 os.chdir(self.test_dir)127 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)128 self.assert_(os.path.exists(self.PO_FILE))129 po_contents = open(self.PO_FILE, 'r').read()130 self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)