django-admin makemessages - excluding folders

1,107 views
Skip to first unread message

Aljosa Mohorovic

unread,
Dec 1, 2008, 7:00:44 PM12/1/08
to Django users
i usually use svn:externals to add django, extensions, evolution and
other stuff to my projects but when i use makemessages in this
situation it generates locale for everything in current folder.
i've added some code to makemessages to enable excluding folders by
pattern to resolve my current situation:
$ django-admin makemessages -l hr --exclude_regex="^\.\/(django|
photologue)"

i'm sure that there is a better way (since this introduces problems
when i update django), any tips?

Aljosa Mohorovic

svn diff:
Index: core/management/commands/makemessages.py
===================================================================
--- core/management/commands/makemessages.py (revision 9538)
+++ core/management/commands/makemessages.py (working copy)
@@ -43,7 +43,7 @@
# trick xgettext to parse them as Python files)
return set([x for x in ext_list if x != '.py'])

-def make_messages(locale=None, domain='django', verbosity='1',
all=False, extensions=None):
+def make_messages(locale=None, domain='django', verbosity='1',
all=False, extensions=None, exclude_regex=None):
"""
Uses the locale directory from the Django SVN tree or an
application/
project to process all
@@ -114,7 +114,15 @@
for (dirpath, dirnames, filenames) in os.walk("."):
all_files.extend([(dirpath, f) for f in filenames])
all_files.sort()
+
+ if exclude_regex != None:
+ exclude_pattern = re.compile(exclude_regex)
for dirpath, file in all_files:
+ if exclude_regex != None:
+ if exclude_pattern.match(dirpath) != None:
+ print 'Excluding folder: ', dirpath
+ continue
+
file_base, file_ext = os.path.splitext(file)
if domain == 'djangojs' and file_ext == '.js':
if verbosity > 1:
@@ -199,6 +207,7 @@
make_option('--verbosity', '-v', action='store',
dest='verbosity',
default='1', type='choice', choices=['0', '1', '2'],
help='Verbosity level; 0=minimal output, 1=normal output,
2=all output'),
+ make_option('--exclude_regex', default=None, help='To exclude
folder(s) provide regex.'),
make_option('--all', '-a', action='store_true', dest='all',
default=False, help='Reexamines all source code and
templates for new translation strings and updates all message files
for all available languages.'),
make_option('--extension', '-e', dest='extensions',
@@ -219,6 +228,7 @@
verbosity = int(options.get('verbosity'))
process_all = options.get('all')
extensions = options.get('extensions') or ['html']
+ exclude_regex = options.get('exclude_regex')

if domain == 'djangojs':
extensions = []
@@ -228,4 +238,4 @@
if '.js' in extensions:
raise CommandError("JavaScript files should be examined
by using the special 'djangojs' domain only.")

- make_messages(locale, domain, verbosity, process_all,
extensions)
+ make_messages(locale, domain, verbosity, process_all,
extensions, exclude_regex)

Malcolm Tredinnick

unread,
Dec 1, 2008, 8:44:33 PM12/1/08
to django...@googlegroups.com

On Mon, 2008-12-01 at 16:00 -0800, Aljosa Mohorovic wrote:
> i usually use svn:externals to add django, extensions, evolution and
> other stuff to my projects but when i use makemessages in this
> situation it generates locale for everything in current folder.
> i've added some code to makemessages to enable excluding folders by
> pattern to resolve my current situation:
> $ django-admin makemessages -l hr --exclude_regex="^\.\/(django|
> photologue)"
>
> i'm sure that there is a better way (since this introduces problems
> when i update django), any tips?

Well, there might be conflicting requirements here, it depends on what
you're really after.

Ticket #7050 is about excluding directories that have their own locale/
directory, which is quite a reasonable idea. Then, if a directory
already has i18n support, it isn't included in the project-level files.
So that probably solves your main problem.

It's not clear that just allowing arbitrary files to be excluded is
something that's a really good idea, since collecting all the strings
for translation is kind of the idea (I'm talking about the case where
there isn't an application-level locale/ directory here). If strings
from some file aren't meant to be included in the PO files, they
wouldn't be marked for translation.

As a practical matter, if you want to maintain something like your
modification without modifying Django, the solution might be to create
your own custom management command. That command will handle the extra
option and then call the default make_messages() function. You could put
that command into an app that contains any other utility code you carry
around from project to project (for example, common template tags, etc).

Regards,
Malcolm


Reply all
Reply to author
Forward
0 new messages