Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
b01544d6
Commit
b01544d6
authored
7 years ago
by
Dmitry Gamanenko
Committed by
0x29a
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add site language config
parent
04babaa6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/dark_lang/middleware.py
+10
-0
10 additions, 0 deletions
openedx/core/djangoapps/dark_lang/middleware.py
openedx/core/djangoapps/dark_lang/tests.py
+11
-0
11 additions, 0 deletions
openedx/core/djangoapps/dark_lang/tests.py
with
21 additions
and
0 deletions
openedx/core/djangoapps/dark_lang/middleware.py
+
10
−
0
View file @
b01544d6
...
...
@@ -16,6 +16,7 @@ from django.utils.deprecation import MiddlewareMixin
from
openedx.core.djangoapps.dark_lang
import
DARK_LANGUAGE_KEY
from
openedx.core.djangoapps.dark_lang.models
import
DarkLangConfig
from
openedx.core.djangoapps.site_configuration.helpers
import
get_value
from
openedx.core.djangoapps.user_api.preferences.api
import
get_user_preference
# If django 1.7 or higher is used, the right-side can be updated with new-style codes.
...
...
@@ -90,8 +91,17 @@ class DarkLangMiddleware(MiddlewareMixin):
return
self
.
_clean_accept_headers
(
request
)
self
.
_set_site_or_microsite_language
(
request
)
self
.
_activate_preview_language
(
request
)
def
_set_site_or_microsite_language
(
self
,
request
):
"""
Apply language specified in site configuration.
"""
language
=
get_value
(
'
LANGUAGE_CODE
'
,
None
)
if
language
:
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
language
def
_fuzzy_match
(
self
,
lang_code
):
"""
Returns a fuzzy match for lang_code
"""
match
=
None
...
...
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/dark_lang/tests.py
+
11
−
0
View file @
b01544d6
...
...
@@ -13,6 +13,7 @@ from django.utils.translation import LANGUAGE_SESSION_KEY
from
openedx.core.djangoapps.dark_lang.middleware
import
DarkLangMiddleware
from
openedx.core.djangoapps.dark_lang.models
import
DarkLangConfig
from
openedx.core.djangoapps.site_configuration.tests.test_util
import
with_site_configuration
from
openedx.core.djangolib.testing.utils
import
CacheIsolationTestCase
from
common.djangoapps.student.tests.factories
import
UserFactory
...
...
@@ -256,6 +257,16 @@ class DarkLangMiddlewareTests(CacheIsolationTestCase):
session
[
LANGUAGE_SESSION_KEY
]
=
session_language
session
.
save
()
@with_site_configuration
(
configuration
=
{
'
LANGUAGE_CODE
'
:
'
rel
'
})
def
test_site_configuration_language
(
self
):
# `LANGUAGE_CODE` in site configuration should override session lang
self
.
_set_client_session_language
(
'
notrel
'
)
self
.
client
.
get
(
'
/home
'
)
self
.
assert_session_lang_equals
(
'
rel
'
,
self
.
client
.
session
)
def
test_preview_lang_with_released_language
(
self
):
# Preview lang should always override selection
self
.
_post_set_preview_lang
(
'
rel
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment