Skip to content

Commit ce05829

Browse files
committed
Merge pull request #3 from EnTeQuAk/master
Tests, cleanups, management command for compile and makemessages
2 parents b3b8819 + 3ddc241 commit ce05829

File tree

15 files changed

+322
-117
lines changed

15 files changed

+322
-117
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
language: python
22
python: 2.7
33
env:
4+
- TOX_ENV=py33-master
45
- TOX_ENV=py33-1.7.x
56
- TOX_ENV=py33-1.6.x
67
- TOX_ENV=py33-1.5.x
8+
- TOX_ENV=pypy-master
9+
- TOX_ENV=pypy-1.7.x
10+
- TOX_ENV=pypy-1.6.x
11+
- TOX_ENV=pypy-1.5.x
12+
- TOX_ENV=py27-master
713
- TOX_ENV=py27-1.7.x
814
- TOX_ENV=py27-1.6.x
915
- TOX_ENV=py27-1.5.x

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Contributors:
1010
- Thomas Grainger <[email protected]>
1111
- Christopher Grebs <[email protected]>
1212

13+
1314
django-babel was previously developed under the Copyright of Edgewall Software.
1415
The following copyright notice holds true for releases before 2013: "Copyright
1516
(c) 2007 - 2011 by Edgewall Software"

CHANGELOG.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Changelog
2+
=========
3+
4+
0.4 - `master`_
5+
---------------
6+
7+
.. note:: This version is not yet released and is under active development.
8+
9+
* Initial testing infrastructure
10+
* Add management command `babel` with `makemessages` and `compilemessages`
11+
labels. Mimics django's `makemessages` and `compilemessages` commands.
12+
13+
14+
0.3.1 - 2013-12-11
15+
------------------
16+
17+
* fix relative import in template tags
18+
19+
20+
0.3.0 - 2013-12-11
21+
------------------
22+
23+
* Rename package to django_babel
24+
25+
26+
0.2.3 - 2013-12-11
27+
------------------
28+
29+
* Rename package on PyPI
30+
* Use GitHub as source control
31+
32+
33+
.. _`master`: https://github.com/graingert/django-babel

CHANGES.rst

Lines changed: 0 additions & 26 deletions
This file was deleted.

django_babel/extract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def extract_django(fileobj, keywords, comment_tags, options):
4747
None,
4848
smart_unicode(u''.join(singular)),
4949
[])
50+
5051
intrans = False
5152
inplural = False
5253
singular = []

django_babel/management/__init__.py

Whitespace-only changes.

django_babel/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#-*- coding: utf-8 -*-
2+
import os
3+
from distutils.dist import Distribution
4+
from optparse import make_option
5+
from subprocess import call
6+
7+
from django.core.management.base import LabelCommand, CommandError
8+
from django.conf import settings
9+
10+
11+
class Command(LabelCommand):
12+
13+
args = '[makemessages] [compilemessages]'
14+
15+
option_list = LabelCommand.option_list + (
16+
make_option(
17+
'--locale', '-l',
18+
default=None, dest='locale', action='append',
19+
help='Creates or updates the message files for the given locale(s)'
20+
' (e.g pt_BR). Can be used multiple times.'),
21+
make_option('--domain', '-d',
22+
default='django', dest='domain',
23+
help='The domain of the message files (default: "django").'),
24+
make_option('--mapping-file', '-F',
25+
default=None, dest='mapping_file',
26+
help='Mapping file')
27+
)
28+
29+
def handle_label(self, command, **options):
30+
if command not in ('makemessages', 'compilemessages'):
31+
raise CommandError(
32+
"You must either apply 'makemessages' or 'compilemessages'"
33+
)
34+
35+
if command == 'makemessages':
36+
self.handle_makemessages(**options)
37+
if command == 'compilemessages':
38+
self.handle_compilemessages(**options)
39+
40+
def handle_makemessages(self, **options):
41+
locale_paths = list(settings.LOCALE_PATHS)
42+
domain = options.pop('domain')
43+
locales = options.pop('locale')
44+
45+
# support for mapping file specification via setup.cfg
46+
# TODO: Try to support all possible options.
47+
distribution = Distribution()
48+
distribution.parse_config_files(distribution.find_config_files())
49+
50+
mapping_file = options.pop('mapping_file', None)
51+
has_extract = 'extract_messages' in distribution.command_options
52+
if mapping_file is None and has_extract:
53+
opts = distribution.command_options['extract_messages']
54+
try:
55+
mapping_file = opts['mapping_file'][1]
56+
except (IndexError, KeyError):
57+
mapping_file = None
58+
59+
for path in locale_paths:
60+
potfile = os.path.join(path, '%s.pot' % domain)
61+
if not os.path.exists(potfile):
62+
continue
63+
64+
cmd = ['pybabel', 'extract', '-o', potfile]
65+
66+
if mapping_file is not None:
67+
cmd.extend(['-F', mapping_file])
68+
69+
cmd.append(os.path.dirname(os.path.relpath(path)))
70+
71+
call(cmd)
72+
73+
for locale in locales:
74+
cmd = ['pybabel', 'update', '-D', domain,
75+
'-i', potfile,
76+
'-d', os.path.relpath(path),
77+
'-l', locale]
78+
call(cmd)
79+
80+
def handle_compilemessages(self, **options):
81+
locale_paths = list(settings.LOCALE_PATHS)
82+
domain = options.pop('domain')
83+
locales = options.pop('locale')
84+
85+
for path in locale_paths:
86+
for locale in locales:
87+
po_file = os.path.join(
88+
path, locale, 'LC_MESSAGES', domain + '.po'
89+
)
90+
if os.path.exists(po_file):
91+
cmd = ['pybabel', 'compile', '-D', domain,
92+
'-d', path, '-l', locale]
93+
call(cmd)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#
44
# django-babel documentation build configuration file, created by

setup.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[pytest]
2+
addopts=-vs --pep8 --flakes
3+
timeout=5
4+
norecursedirs=.tox
5+
pep8ignore =
6+
*.py E128
7+
docs/conf.py ALL
8+
tests/*.py ALL
9+
flakes-ignore =
10+
docs/conf.py ALL
11+
tests/*.py ALL
12+
13+
[flake8]
14+
ignore = E128
15+
exclude = .tox,.git,docs/conf.py,tests/*.py
16+
17+
[wheel]
18+
universal = 1

0 commit comments

Comments
 (0)