Ticket #16903: no-location-3.patch
File no-location-3.patch, 7.9 KB (added by , 13 years ago) |
---|
-
docs/ref/django-admin.txt
475 475 Use the ``--no-wrap`` option to disable breaking long message lines into 476 476 several lines in language files. 477 477 478 .. django-admin-option:: --no-location 479 480 .. versionadded:: 1.4 481 482 Use the ``--no-location`` option to not write ``#: filename:line`` 483 comment lines in language files. 484 478 485 reset <appname appname ...> 479 486 --------------------------- 480 487 -
django/core/management/commands/makemessages.py
115 115 116 116 def make_messages(locale=None, domain='django', verbosity='1', all=False, 117 117 extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False, 118 no_location=False, 118 119 no_obsolete=False): 119 120 """ 120 121 Uses the locale directory from the Django SVN tree or an application/ … … 163 164 languages = [os.path.basename(l) for l in locale_dirs] 164 165 165 166 wrap = no_wrap and '--no-wrap' or '' 167 location = no_location and '--no-location' or '' 166 168 167 169 for locale in languages: 168 170 if verbosity > 0: … … 191 193 finally: 192 194 f.close() 193 195 cmd = ( 194 'xgettext -d %s -L C %s --keyword=gettext_noop '196 'xgettext -d %s -L C %s %s --keyword=gettext_noop ' 195 197 '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 ' 196 198 '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 ' 197 199 '--from-code UTF-8 --add-comments=Translators -o - "%s"' % ( 198 domain, wrap, os.path.join(dirpath, thefile)200 domain, wrap, location, os.path.join(dirpath, thefile) 199 201 ) 200 202 ) 201 203 msgs, errors = _popen(cmd) … … 235 237 if verbosity > 1: 236 238 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 237 239 cmd = ( 238 'xgettext -d %s -L Python %s --keyword=gettext_noop '240 'xgettext -d %s -L Python %s %s --keyword=gettext_noop ' 239 241 '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 ' 240 242 '--keyword=ugettext_noop --keyword=ugettext_lazy ' 241 243 '--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 ' 242 244 '--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 ' 243 245 '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 ' 244 246 '--add-comments=Translators -o - "%s"' % ( 245 domain, wrap, os.path.join(dirpath, thefile))247 domain, wrap, location, os.path.join(dirpath, thefile)) 246 248 ) 247 249 msgs, errors = _popen(cmd) 248 250 if errors: … … 272 274 os.unlink(os.path.join(dirpath, thefile)) 273 275 274 276 if os.path.exists(potfile): 275 msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %276 (wrap, potfile))277 msgs, errors = _popen('msguniq %s %s --to-code=utf-8 "%s"' % 278 (wrap, location, potfile)) 277 279 if errors: 278 280 os.unlink(potfile) 279 281 raise CommandError( … … 284 286 f.write(msgs) 285 287 finally: 286 288 f.close() 287 msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %288 (wrap, pofile, potfile))289 msgs, errors = _popen('msgmerge %s %s -q "%s" "%s"' % 290 (wrap, location, pofile, potfile)) 289 291 if errors: 290 292 os.unlink(potfile) 291 293 raise CommandError( … … 301 303 f.close() 302 304 os.unlink(potfile) 303 305 if no_obsolete: 304 msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %305 (wrap, pofile, pofile))306 msgs, errors = _popen('msgattrib %s %s -o "%s" --no-obsolete "%s"' % 307 (wrap, location, pofile, pofile)) 306 308 if errors: 307 309 raise CommandError( 308 310 "errors happened while running msgattrib\n%s" % errors) … … 327 329 default=True, help="Don't ignore the common glob-style patterns 'CVS', '.*' and '*~'."), 328 330 make_option('--no-wrap', action='store_true', dest='no_wrap', 329 331 default=False, help="Don't break long message lines into several lines"), 332 make_option('--no-location', action='store_true', dest='no_location', 333 default=False, help="Don't write '#: filename:line' lines"), 330 334 make_option('--no-obsolete', action='store_true', dest='no_obsolete', 331 335 default=False, help="Remove obsolete message strings"), 332 336 ) … … 351 355 ignore_patterns += ['CVS', '.*', '*~'] 352 356 ignore_patterns = list(set(ignore_patterns)) 353 357 no_wrap = options.get('no_wrap') 358 no_location = options.get('no_location') 354 359 no_obsolete = options.get('no_obsolete') 355 360 if domain == 'djangojs': 356 361 extensions = handle_extensions(extensions or ['js']) … … 361 366 sys.stdout.write('examining files with the extensions: %s\n' 362 367 % get_text_list(list(extensions), 'and')) 363 368 364 make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_ obsolete)369 make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_location, no_obsolete) -
tests/regressiontests/i18n/commands/extraction.py
214 214 self.assertTrue(os.path.exists(self.PO_FILE)) 215 215 po_contents = open(self.PO_FILE, 'r').read() 216 216 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) 217 218 219 class NoLocationExtractorTests(ExtractorTests): 220 221 def test_no_location_enabled(self): 222 os.chdir(self.test_dir) 223 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True) 224 self.assertTrue(os.path.exists(self.PO_FILE)) 225 po_contents = open(self.PO_FILE, 'r').read() 226 self.assertFalse('#: templates/test.html:55' in po_contents) 227 228 def test_no_location_disabled(self): 229 os.chdir(self.test_dir) 230 management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False) 231 self.assertTrue(os.path.exists(self.PO_FILE)) 232 po_contents = open(self.PO_FILE, 'r').read() 233 self.assertTrue('#: templates/test.html:55' in po_contents) -
tests/regressiontests/i18n/tests.py
28 28 if can_run_extraction_tests: 29 29 from .commands.extraction import (ExtractorTests, BasicExtractorTests, 30 30 JavascriptExtractorTests, IgnoredExtractorTests, SymlinkExtractorTests, 31 CopyPluralFormsExtractorTests, NoWrapExtractorTests) 31 CopyPluralFormsExtractorTests, NoWrapExtractorTests, 32 NoLocationExtractorTests) 32 33 if can_run_compilation_tests: 33 34 from .commands.compilation import MessageCompilationTests, PoFileTests 34 35 from .contenttypes.tests import ContentTypeTests