Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat(LC-v2): select language" #758

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading