Ticket #18731: makemessages-master.patch
File makemessages-master.patch, 8.4 KB (added by , 12 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 a7e9817..72d8dd3 100644
a b class TranslatableFile(object): 42 42 return self.file < other.file 43 43 return self.dirpath < other.dirpath 44 44 45 def process(self, command, potfile, domain, keep_pot=False ):45 def process(self, command, potfile, domain, keep_pot=False, extra_keywords=None): 46 46 """ 47 47 Extract translatable literals from self.file for :param domain: 48 48 creating or updating the :param potfile: POT file. … … class TranslatableFile(object): 73 73 '--keyword=gettext_lazy', 74 74 '--keyword=ngettext_lazy:1,2', 75 75 '--keyword=pgettext:1c,2', 76 '--keyword=npgettext:1c,2,3', 76 '--keyword=npgettext:1c,2,3' 77 ] 78 if extra_keywords: 79 for kw in extra_keywords: 80 args.append('--keyword=%s' % kw) 81 args += [ 77 82 '--from-code=UTF-8', 78 83 '--add-comments=Translators', 79 84 '--output=-' … … class TranslatableFile(object): 108 113 '--keyword=pgettext:1c,2', 109 114 '--keyword=npgettext:1c,2,3', 110 115 '--keyword=pgettext_lazy:1c,2', 111 '--keyword=npgettext_lazy:1c,2,3', 116 '--keyword=npgettext_lazy:1c,2,3' 117 ] 118 if extra_keywords: 119 for kw in extra_keywords: 120 args.append('--keyword=%s' % kw) 121 args += [ 112 122 '--from-code=UTF-8', 113 123 '--add-comments=Translators', 114 124 '--output=-' … … class Command(NoArgsCommand): 182 192 default=False, help="Remove obsolete message strings."), 183 193 make_option('--keep-pot', action='store_true', dest='keep_pot', 184 194 default=False, help="Keep .pot file after making messages. Useful when debugging."), 195 make_option('--extra-keyword', dest='extra_keywords', action='append', 196 help='If you use import aliases for ugettext and its variations, ' 197 'you can specify it here to make sure that xgettext will find ' 198 'your translatable strings.'), 185 199 ) 186 200 help = ("Runs over the entire source tree of the current directory and " 187 201 "pulls out all strings marked for translation. It creates (or updates) a message " … … class Command(NoArgsCommand): 207 221 self.location = '--no-location' if options.get('no_location') else '' 208 222 self.no_obsolete = options.get('no_obsolete') 209 223 self.keep_pot = options.get('keep_pot') 224 self.extra_keywords = options.get('extra_keywords') 210 225 211 226 if self.domain not in ('django', 'djangojs'): 212 227 raise CommandError("currently makemessages only supports domains " … … class Command(NoArgsCommand): 294 309 os.unlink(potfile) 295 310 296 311 for f in file_list: 297 f.process(self, potfile, self.domain, self.keep_pot )312 f.process(self, potfile, self.domain, self.keep_pot, self.extra_keywords) 298 313 return potfile 299 314 300 315 def find_files(self, root): -
docs/man/django-admin.1
diff --git a/docs/man/django-admin.1 b/docs/man/django-admin.1 index 4d937b4..2d4abbf 100644
a b Executes 60 60 .B sqlall 61 61 for the given app(s) in the current database. 62 62 .TP 63 .BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\-extension=EXTENSION" "] [" "\-\-all" "] [" "\-\-symlinks" "] [" "\-\-ignore=PATTERN" "] [" "\-\-no\-default\-ignore" "] [" "\-\-no\-wrap" "] [" "\-\-no\-location" "] "63 .BI "makemessages [" "\-\-locale=LOCALE" "] [" "\-\-domain=DOMAIN" "] [" "\-\-extension=EXTENSION" "] [" "\-\-all" "] [" "\-\-symlinks" "] [" "\-\-ignore=PATTERN" "] [" "\-\-no\-default\-ignore" "] [" "\-\-no\-wrap" "] [" "\-\-no\-location" "] [" "\-\-extra\-keyword" "]" 64 64 Runs over the entire source tree of the current directory and pulls out all 65 65 strings marked for translation. It creates (or updates) a message file in the 66 66 conf/locale (in the django tree) or locale (for project and application) directory. -
docs/ref/django-admin.txt
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 6277b22..fb85eae 100644
a b Use the ``--keep-pot`` option to prevent django from deleting the temporary 520 520 .pot file it generates before creating the .po file. This is useful for 521 521 debugging errors which may prevent the final language files from being created. 522 522 523 .. django-admin-option:: --extra-keyword 524 525 .. versionadded:: 1.6 526 527 When you import the ``ugettext`` and ``ugettext_lazy`` functions as aliases, 528 ``makemessages`` may not find translatable strings in your python source code. 529 With the ``--extra-keyword`` option, you can force it to look for other aliases 530 you may choose. 531 532 Example usage: 533 534 If you want ``makemessages`` to find translatable strings in the following 535 python code. 536 537 .. code-block:: python 538 539 from django.utils.translation import ugettext as tr, ugettext_lazy as tr_lazy 540 541 tr('some translatable string') 542 tr_lazy('some lazy translatable string') 543 544 You will need to add the option ``--extra-keyword`` twice:: 545 546 django-admin.py makemessages --locale=fr_FR --extra-keyword=tr --extra-keyword=tr_lazy 547 548 .. note:: The default alias ``'_'`` will allways be detected by ``makemessages`` 549 whether you use the ``--extra-keyword`` option or not. 550 551 523 552 runfcgi [options] 524 553 ----------------- 525 554 -
tests/i18n/commands/extraction.py
diff --git a/tests/i18n/commands/extraction.py b/tests/i18n/commands/extraction.py index 80e4ee0..83060e3 100644
a b class MultipleLocaleExtractionTests(ExtractorTests): 423 423 management.call_command('makemessages', locale='pt,de,ch', verbosity=0) 424 424 self.assertTrue(os.path.exists(self.PO_FILE_PT)) 425 425 self.assertTrue(os.path.exists(self.PO_FILE_DE)) 426 427 428 class UgettextAliasesTests(ExtractorTests): 429 430 def test_missing_keyword(self): 431 os.chdir(self.test_dir) 432 shutil.copyfile('./ugettext-aliases.sample', './ugettext_aliases.py') 433 management.call_command('makemessages', locale=LOCALE, verbosity=0) 434 self.assertTrue(os.path.exists(self.PO_FILE)) 435 with open(self.PO_FILE, 'r') as fp: 436 po_contents = force_text(fp.read()) 437 self.assertNotMsgId('Should be found only with the --extra-keyword option', po_contents) 438 self.assertNotMsgId('Lazy, should be found only with the --extra-keyword option', po_contents) 439 os.remove('./ugettext_aliases.py') 440 441 def test_added_keywords(self): 442 os.chdir(self.test_dir) 443 shutil.copyfile('./ugettext-aliases.sample', './ugettext_aliases.py') 444 management.call_command('makemessages', locale=LOCALE, verbosity=0, extra_keywords=['tr', 'tr_lazy']) 445 self.assertTrue(os.path.exists(self.PO_FILE)) 446 with open(self.PO_FILE, 'r') as fp: 447 po_contents = force_text(fp.read()) 448 self.assertMsgId('Should be found only with the --extra-keyword option', po_contents) 449 self.assertMsgId('Lazy, should be found only with the --extra-keyword option', po_contents) 450 os.remove('./ugettext_aliases.py') -
new file tests/i18n/commands/ugettext-aliases.sample
diff --git a/tests/i18n/commands/ugettext-aliases.sample b/tests/i18n/commands/ugettext-aliases.sample new file mode 100644 index 0000000..17c61fe
- + 1 from django.utils.translation import ugettext as tr, ugettext_lazy as tr_lazy 2 3 tr('Should be found only with the --extra-keyword option') 4 tr_lazy('Lazy, should be found only with the --extra-keyword option') -
tests/i18n/tests.py
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index d26a201..89baa7a 100644
a b if can_run_extraction_tests: 38 38 JavascriptExtractorTests, IgnoredExtractorTests, SymlinkExtractorTests, 39 39 CopyPluralFormsExtractorTests, NoWrapExtractorTests, 40 40 NoLocationExtractorTests, KeepPotFileExtractorTests, 41 MultipleLocaleExtractionTests )41 MultipleLocaleExtractionTests, UgettextAliasesTests) 42 42 if can_run_compilation_tests: 43 43 from .commands.compilation import (PoFileTests, PoFileContentsTests, 44 44 PercentRenderingTests, MultipleLocaleCompilationTests,