Author: julien
Date: 2011-11-11 05:07:14 -0800 (Fri, 11 Nov 2011)
New Revision: 17081
Modified:
django/trunk/django/core/management/commands/makemessages.py
django/trunk/docs/ref/django-admin.txt
django/trunk/docs/releases/1.4.txt
django/trunk/tests/regressiontests/i18n/commands/extraction.py
django/trunk/tests/regressiontests/i18n/tests.py
Log:
Fixed #16903 -- Added `--no-location` option to the `makemessages` command to
not write '#: filename:line' comment lines in language files. Thanks to alpar
for the suggestion and patch.
Modified: django/trunk/django/core/management/commands/makemessages.py
===================================================================
--- django/trunk/django/core/management/commands/makemessages.py
2011-11-11 12:25:53 UTC (rev 17080)
+++ django/trunk/django/core/management/commands/makemessages.py
2011-11-11 13:07:14 UTC (rev 17081)
@@ -115,6 +115,7 @@
def make_messages(locale=None, domain='django', verbosity='1', all=False,
extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False,
+ no_location=False,
no_obsolete=False):
"""
Uses the locale directory from the Django SVN tree or an application/
@@ -163,6 +164,7 @@
languages = [os.path.basename(l) for l in locale_dirs]
wrap = no_wrap and '--no-wrap' or ''
+ location = no_location and '--no-location' or ''
for locale in languages:
if verbosity > 0:
@@ -191,11 +193,11 @@
finally:
f.close()
cmd = (
- 'xgettext -d %s -L C %s --keyword=gettext_noop '
+ 'xgettext -d %s -L C %s %s --keyword=gettext_noop '
'--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
'--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 '
'--from-code UTF-8 --add-comments=Translators -o - "%s"' %
(
- domain, wrap, os.path.join(dirpath, thefile)
+ domain, wrap, location, os.path.join(dirpath, thefile)
)
)
msgs, errors = _popen(cmd)
@@ -235,14 +237,14 @@
if verbosity > 1:
sys.stdout.write('processing file %s in %s\n' % (file,
dirpath))
cmd = (
- 'xgettext -d %s -L Python %s --keyword=gettext_noop '
+ 'xgettext -d %s -L Python %s %s --keyword=gettext_noop '
'--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
'--keyword=ugettext_noop --keyword=ugettext_lazy '
'--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 '
'--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 '
'--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 '
'--add-comments=Translators -o - "%s"' % (
- domain, wrap, os.path.join(dirpath, thefile))
+ domain, wrap, location, os.path.join(dirpath, thefile))
)
msgs, errors = _popen(cmd)
if errors:
@@ -272,8 +274,8 @@
os.unlink(os.path.join(dirpath, thefile))
if os.path.exists(potfile):
- msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
- (wrap, potfile))
+ msgs, errors = _popen('msguniq %s %s --to-code=utf-8 "%s"' %
+ (wrap, location, potfile))
if errors:
os.unlink(potfile)
raise CommandError(
@@ -284,8 +286,8 @@
f.write(msgs)
finally:
f.close()
- msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
- (wrap, pofile, potfile))
+ msgs, errors = _popen('msgmerge %s %s -q "%s" "%s"' %
+ (wrap, location, pofile, potfile))
if errors:
os.unlink(potfile)
raise CommandError(
@@ -301,8 +303,8 @@
f.close()
os.unlink(potfile)
if no_obsolete:
- msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete
"%s"' %
- (wrap, pofile, pofile))
+ msgs, errors = _popen('msgattrib %s %s -o "%s" --no-obsolete
"%s"' %
+ (wrap, location, pofile, pofile))
if errors:
raise CommandError(
"errors happened while running msgattrib\n%s" % errors)
@@ -327,6 +329,8 @@
default=True, help="Don't ignore the common glob-style patterns
'CVS', '.*' and '*~'."),
make_option('--no-wrap', action='store_true', dest='no_wrap',
default=False, help="Don't break long message lines into several
lines"),
+ make_option('--no-location', action='store_true', dest='no_location',
+ default=False, help="Don't write '#: filename:line' lines"),
make_option('--no-obsolete', action='store_true', dest='no_obsolete',
default=False, help="Remove obsolete message strings"),
)
@@ -351,6 +355,7 @@
ignore_patterns += ['CVS', '.*', '*~']
ignore_patterns = list(set(ignore_patterns))
no_wrap = options.get('no_wrap')
+ no_location = options.get('no_location')
no_obsolete = options.get('no_obsolete')
if domain == 'djangojs':
extensions = handle_extensions(extensions or ['js'])
@@ -361,4 +366,4 @@
sys.stdout.write('examining files with the extensions: %s\n'
% get_text_list(list(extensions), 'and'))
- make_messages(locale, domain, verbosity, process_all, extensions,
symlinks, ignore_patterns, no_wrap, no_obsolete)
+ make_messages(locale, domain, verbosity, process_all, extensions,
symlinks, ignore_patterns, no_wrap, no_location, no_obsolete)
Modified: django/trunk/docs/ref/django-admin.txt
===================================================================
--- django/trunk/docs/ref/django-admin.txt 2011-11-11 12:25:53 UTC (rev
17080)
+++ django/trunk/docs/ref/django-admin.txt 2011-11-11 13:07:14 UTC (rev
17081)
@@ -475,6 +475,14 @@
Use the ``--no-wrap`` option to disable breaking long message lines into
several lines in language files.
+.. django-admin-option:: --no-location
+
+.. versionadded:: 1.4
+
+Use the ``--no-location`` option to not write '``#: filename:line``'
+comment lines in language files. Note that using this option makes it harder
+for technically skilled translators to understand each message's context.
+
reset <appname appname ...>
---------------------------
Modified: django/trunk/docs/releases/1.4.txt
===================================================================
--- django/trunk/docs/releases/1.4.txt 2011-11-11 12:25:53 UTC (rev 17080)
+++ django/trunk/docs/releases/1.4.txt 2011-11-11 13:07:14 UTC (rev 17081)
@@ -477,6 +477,9 @@
This should make it easier to read when debugging interaction with
client-side Javascript code.
+* Added the :djadminopt:`--no-location` option to the :djadmin:`makemessages`
+ command.
+
.. _backwards-incompatible-changes-1.4:
Backwards incompatible changes in 1.4
Modified: django/trunk/tests/regressiontests/i18n/commands/extraction.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/commands/extraction.py
2011-11-11 12:25:53 UTC (rev 17080)
+++ django/trunk/tests/regressiontests/i18n/commands/extraction.py
2011-11-11 13:07:14 UTC (rev 17081)
@@ -214,3 +214,20 @@
self.assertTrue(os.path.exists(self.PO_FILE))
po_contents = open(self.PO_FILE, 'r').read()
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)
+
+
+class NoLocationExtractorTests(ExtractorTests):
+
+ def test_no_location_enabled(self):
+ os.chdir(self.test_dir)
+ management.call_command('makemessages', locale=LOCALE, verbosity=0,
no_location=True)
+ self.assertTrue(os.path.exists(self.PO_FILE))
+ po_contents = open(self.PO_FILE, 'r').read()
+ self.assertFalse('#: templates/test.html:55' in po_contents)
+
+ def test_no_location_disabled(self):
+ os.chdir(self.test_dir)
+ management.call_command('makemessages', locale=LOCALE, verbosity=0,
no_location=False)
+ self.assertTrue(os.path.exists(self.PO_FILE))
+ po_contents = open(self.PO_FILE, 'r').read()
+ self.assertTrue('#: templates/test.html:55' in po_contents)
Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py 2011-11-11 12:25:53 UTC
(rev 17080)
+++ django/trunk/tests/regressiontests/i18n/tests.py 2011-11-11 13:07:14 UTC
(rev 17081)
@@ -28,7 +28,8 @@
if can_run_extraction_tests:
from .commands.extraction import (ExtractorTests, BasicExtractorTests,
JavascriptExtractorTests, IgnoredExtractorTests, SymlinkExtractorTests,
- CopyPluralFormsExtractorTests, NoWrapExtractorTests)
+ CopyPluralFormsExtractorTests, NoWrapExtractorTests,
+ NoLocationExtractorTests)
if can_run_compilation_tests:
from .commands.compilation import MessageCompilationTests, PoFileTests
from .contenttypes.tests import ContentTypeTests
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.