Skip to content

Commit

Permalink
Merge pull request #21 from julen/feature/use_i18n
Browse files Browse the repository at this point in the history
Add support for `USE_I18N = False`
  • Loading branch information
Sébastien Fievet committed Aug 2, 2016
2 parents c5ee937 + b1f80a0 commit 350aaa3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

v.next (unreleased)
-------------------

* Added support for `USE_18N = False` (#19).

v1.1.5 (2015 Aug 7)
-------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Collect JavaScript catalog files in a single location.
Some commonly used options are:

``-l LOCALE`` or ``--locale=LOCALE``
The locale to process. Default is to process all.
The locale to process. Default is to process all but if for some reason I18N
features are disabled, only `settings.LANGUAGE_CODE` will be processed.

``-d DOMAIN`` or ``--domain=DOMAIN``
Override the gettext domain. By default, the command uses the ``djangojs``
Expand Down
6 changes: 5 additions & 1 deletion src/statici18n/management/commands/compilejsi18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--locale', '-l', dest='locale',
help="The locale to process. Default is to process all."),
help="The locale to process. Default is to process all "
"but if for some reason I18N features are disabled, "
"only `settings.LANGUAGE_CODE` will be processed."),
make_option('-d', '--domain',
dest='domain', default=settings.STATICI18N_DOMAIN,
help="Override the gettext domain. By default, "
Expand Down Expand Up @@ -55,6 +57,8 @@ def handle_noargs(self, **options):

if locale is not None:
languages = [locale]
elif not settings.USE_I18N:
languages = [settings.LANGUAGE_CODE]
else:
languages = [to_locale(lang_code)
for (lang_code, lang_name) in settings.LANGUAGES]
Expand Down
20 changes: 20 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ def test_compile_all(settings):
assert '"Hello world!": "Bonjour \\u00e0 tous !"' in content


@pytest.mark.parametrize('locale', ['en-us', 'en', 'de'])
def test_compile_no_use_i18n(settings, locale):
"""Tests compilation when `USE_I18N = False`.
In this scenario, only the `settings.LANGUAGE_CODE` locale is processed
(it defaults to `en-us` for Django projects).
"""
settings.USE_I18N = False
settings.LANGUAGE_CODE = locale

out = six.StringIO()
management.call_command('compilejsi18n', verbosity=1, stdout=out)
out.seek(0)
lines = [l.strip() for l in out.readlines()]
assert len(lines) == 1
assert lines[0] == "processing language %s" % locale
assert os.path.exists(os.path.join(
settings.STATIC_ROOT, "jsi18n", locale, "djangojs.js"))


@pytest.mark.usefixtures("cleandir")
def test_compile_locale_not_exists():
out = six.StringIO()
Expand Down

0 comments on commit 350aaa3

Please sign in to comment.