Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16903 -- Added `--no-location` option to the `makemessages` co…

…mmand to not write '#: filename:line' comment lines in language files. Thanks to alpar for the suggestion and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17081 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c3df840c20cc17ceb8fdcafb4215a6f3fb87fed1 1 parent 9d410ee
Julien Phalip authored November 11, 2011
27  django/core/management/commands/makemessages.py
@@ -115,6 +115,7 @@ def copy_plural_forms(msgs, locale, domain, verbosity):
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,6 +164,7 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,11 +193,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,14 +237,14 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,8 +274,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,8 +286,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,8 +303,8 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
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,6 +329,8 @@ class Command(NoArgsCommand):
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,6 +355,7 @@ def handle_noargs(self, *args, **options):
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,4 +366,4 @@ def handle_noargs(self, *args, **options):
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)
8  docs/ref/django-admin.txt
@@ -475,6 +475,14 @@ Use the ``--no-default-ignore`` option to disable the default values of
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. Note that using this option makes it harder
  484
+for technically skilled translators to understand each message's context.
  485
+
478 486
 reset <appname appname ...>
479 487
 ---------------------------
480 488
 
3  docs/releases/1.4.txt
@@ -477,6 +477,9 @@ Django 1.4 also includes several smaller improvements worth noting:
477 477
   This should make it easier to read when debugging interaction with
478 478
   client-side Javascript code.
479 479
 
  480
+* Added the :djadminopt:`--no-location` option to the :djadmin:`makemessages`
  481
+  command.
  482
+
480 483
 .. _backwards-incompatible-changes-1.4:
481 484
 
482 485
 Backwards incompatible changes in 1.4
17  tests/regressiontests/i18n/commands/extraction.py
@@ -214,3 +214,20 @@ def test_no_wrap_disabled(self):
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)
3  tests/regressiontests/i18n/tests.py
@@ -28,7 +28,8 @@
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

0 notes on commit c3df840

Please sign in to comment.
Something went wrong with that request. Please try again.