Skip to content

Commit

Permalink
Merge pull request #758 from eduNEXT/lfc/nuez-saas-lc-v2-2
Browse files Browse the repository at this point in the history
Revert "feat(LC-v2): select language"
  • Loading branch information
luisfelipec95 committed Jul 12, 2023
2 parents 858d1db + 2338ac4 commit 816d295
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
13 changes: 2 additions & 11 deletions openedx/core/djangoapps/dark_lang/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ def beta_langs(self):

def process_request(self, request):
"""
eduNEXT: this middleware will always process the requests.
The model has been modified to not even attempt the db lookup
Prevent user from requesting un-released languages except by using the preview-lang query string.
"""
if not settings.FEATURES.get("EDNX_SITE_AWARE_LOCALE", False) and not DarkLangConfig.current().enabled:
if not DarkLangConfig.current().enabled:
return

self._clean_accept_headers(request)
Expand Down Expand Up @@ -138,13 +137,8 @@ def _clean_accept_headers(self, request):
Remove any language that is not either in ``self.released_langs`` or
a territory of one of those languages.
"""
ednx_locale = settings.FEATURES.get("EDNX_SITE_AWARE_LOCALE", False)
accept = request.META.get('HTTP_ACCEPT_LANGUAGE', None)
if accept is None or accept == '*':
if ednx_locale:
# eduNEXT: return the site aware settings.LANGUAGE_CODE
# so that django.utils.locale.LocaleMiddleware can pick it up
request.META['HTTP_ACCEPT_LANGUAGE'] = f"{settings.LANGUAGE_CODE};q=0.1"
return

new_accept = []
Expand All @@ -153,9 +147,6 @@ def _clean_accept_headers(self, request):
if fuzzy_code:
# Formats lang and priority into a valid accept header fragment.
new_accept.append(f"{fuzzy_code};q={priority}")
elif ednx_locale:
# eduNEXT: if there is no match, we set it to the settings.LANGUAGE_CODE
new_accept.append(f"{settings.LANGUAGE_CODE};q=0.1")

new_accept = ", ".join(new_accept)

Expand Down
13 changes: 3 additions & 10 deletions openedx/core/djangoapps/dark_lang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


from config_models.models import ConfigurationModel
from django.conf import settings
from django.db import models


Expand Down Expand Up @@ -36,19 +35,13 @@ def released_languages_list(self):
``released_languages`` as a list of language codes.
Example: ['it', 'de-at', 'es', 'pt-br']
eduNEXT: we support only the list of available languages from the site
otherwise is the same as having no configuration
"""
released_languages = self.released_languages

if settings.FEATURES.get("EDNX_SITE_AWARE_LOCALE", False):
released_languages = getattr(settings, "released_languages", "")
if not self.released_languages.strip():
return []

languages = [lang.lower().strip() for lang in released_languages.split(',')]
languages = [lang.lower().strip() for lang in self.released_languages.split(',')]
# Put in alphabetical order
languages.sort()

return languages

@property
Expand Down

0 comments on commit 816d295

Please sign in to comment.