Skip to content

Commit

Permalink
listen to settings.LANGUAGES if its different to global_settings.LANG…
Browse files Browse the repository at this point in the history
…UAGES, incorporate them into langs as well as settings.DISTILL_LANGUAGES, related to #80
  • Loading branch information
meeb committed Jun 28, 2024
1 parent a0a45f7 commit 1b37071
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions django_distill/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from shutil import copy2
from concurrent.futures import ThreadPoolExecutor
from django.utils.translation import activate as activate_lang
from django.conf import settings
from django.conf import settings, global_settings
from django.urls import include as include_urls, get_resolver
from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed
from django.utils.module_loading import import_string
Expand Down Expand Up @@ -225,13 +225,21 @@ def render(self, view_name=None, status_codes=None, view_args=None, view_kwargs=

def get_langs(self):
langs = []
default_lang = str(getattr(settings, 'LANGUAGE_CODE', 'en'))
LANGUAGE_CODE = str(getattr(settings, 'LANGUAGE_CODE', 'en'))
GLOBAL_LANGUAGES = list(getattr(global_settings, 'LANGUAGES', []))
try:
DISTILL_LANGUAGES = list(getattr(settings, 'DISTILL_LANGUAGES', []))
LANGUAGES = list(getattr(settings, 'LANGUAGES', []))
except (ValueError, TypeError, AttributeError):
LANGUAGES = []
try:
DISTILL_LANGUAGES = list(getattr(settings, 'DISTILL_LANGUAGES', []))
except (ValueError, TypeError, AttributeError) as e:
DISTILL_LANGUAGES = []
if default_lang not in DISTILL_LANGUAGES:
langs.append(default_lang)
if LANGUAGES != GLOBAL_LANGUAGES:
for lang_code, lang_name in LANGUAGES:
langs.append(lang_code)
if LANGUAGE_CODE not in DISTILL_LANGUAGES and LANGUAGE_CODE not in langs:
langs.append(LANGUAGE_CODE)
for lang in DISTILL_LANGUAGES:
langs.append(lang)
return langs
Expand Down

0 comments on commit 1b37071

Please sign in to comment.