Skip to content

Commit c66c815

Browse files
committed
Implement babel compilemessages command
1 parent 3f5a84a commit c66c815

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

django_babel/extract.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,11 @@ def extract_django(fileobj, keywords, comment_tags, options):
3535
pluralmatch = plural_re.match(t.contents)
3636
if endbmatch:
3737
if inplural:
38-
yield (
39-
lineno,
40-
'ngettext',
41-
(smart_unicode(u''.join(singular)),
42-
smart_unicode(u''.join(plural))),
43-
[])
38+
yield lineno, 'ngettext', (smart_unicode(u''.join(singular)),
39+
smart_unicode(u''.join(plural))), []
4440
else:
45-
yield (
46-
lineno,
47-
None,
48-
smart_unicode(u''.join(singular)),
49-
[])
41+
yield lineno, None, smart_unicode(u''.join(singular)), []
42+
5043
intrans = False
5144
inplural = False
5245
singular = []

django_babel/management/commands/babel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def handle_label(self, command, **options):
2828

2929
if command == 'makemessages':
3030
self.handle_makemessages(**options)
31+
if command == 'compilemessages':
32+
self.handle_compilemessages(**options)
3133

3234
def handle_makemessages(self, **options):
3335
locale_paths = list(settings.LOCALE_PATHS)
@@ -70,3 +72,15 @@ def handle_makemessages(self, **options):
7072
'-l', locale]
7173
print cmd
7274
call(cmd)
75+
76+
def handle_compilemessages(self, **options):
77+
locale_paths = list(settings.LOCALE_PATHS)
78+
domain = options.pop('domain')
79+
locales = options.pop('locale')
80+
81+
for path in locale_paths:
82+
for locale in locales:
83+
po_file = os.path.join(path, locale, 'LC_MESSAGES', domain + '.po')
84+
if os.path.exists(po_file):
85+
cmd = ['pybabel', 'compile', '-D', domain, '-d', path, '-l', locale]
86+
call(cmd)

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def read(*parts):
3232
]
3333

3434

35-
3635
class PyTest(TestCommand):
3736

3837
def finalize_options(self):

0 commit comments

Comments
 (0)