Skip to content

Commit

Permalink
switch to using settings.DISTILL_LANGUAGES for distilling i18n URLs, …
Browse files Browse the repository at this point in the history
…related to #80
  • Loading branch information
meeb committed May 25, 2024
1 parent fd570c9 commit c242eb1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ use `distill_path` or `distill_re_path` if you're building a new site now.
Internationalization is only supported for URLs, page content is unable to be
dynamically translated. By default your site will be generated using the
`LANGUAGE_CODE` value in your `settings.py`. If you also set `settings.USE_I18N` to
`True` then set other languages in your `settings.LANGUAGES` value and register
`True` then set other language codes in your `settings.DISTILL_LANGUAGES` value and register
URLs with `i18n_patterns(...)` then your site will be generated in multiple languges.
This assumes your multi-language site works as expected before adding `django-distill`.

Expand All @@ -260,10 +260,10 @@ If you have something like this in your `settings.py` instead:
```python
USE_I18N = True

LANGUAGES = [
('en', 'English'),
('fr', 'French'),
('de', 'German'),
DISTILL_LANGUAGES = [
'en',
'fr',
'de',
]
```

Expand Down Expand Up @@ -445,6 +445,20 @@ copying directories containing files from apps you're not using that get bundled
to `['some_dir']` the static files directory `static/some_dir` would be skipped.


**DISTILL_LANGUAGES**: list, defaults to `[]`

```python
DISTILL_LANGUAGES = [
'en',
'fr',
'de',
]
```

Set `DISTILL_LANGUAGES` to a list of language codes to attempt to render URLs with.
See the "Internationalization" section for more details.


# Developing locally with HTTPS

If you are using a local development environment which has HTTPS support you may need
Expand Down
16 changes: 11 additions & 5 deletions django_distill/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,17 @@ def render(self, view_name=None, status_codes=None, view_args=None, view_kwargs=

def get_langs(self):
langs = []
if settings.LANGUAGES:
for code, name in settings.LANGUAGES:
langs.append(code)
else:
langs.append(settings.LANGUAGE_CODE)
default_lang = str(getattr(settings, 'LANGUAGE_CODE', 'en'))
try:
DISTILL_LANGUAGES = list(getattr(settings, 'DISTILL_LANGUAGES', []))
except (ValueError, TypeError):
DISTILL_LANGUAGES = []
if default_lang not in DISTILL_LANGUAGES:
langs.append(default_lang)
for lang in settings.LANGUAGES:
if len(lang) != 2:
raise DistillError('Invalid settings.LANGUAGES value')
langs.append(lang[0])
return langs

def _get_filename(self, file_name, uri, param_set):
Expand Down

0 comments on commit c242eb1

Please sign in to comment.