openedx.core.djangoapps.dark_lang package#
Submodules#
openedx.core.djangoapps.dark_lang.middleware module#
Middleware for dark-launching languages. These languages won’t be used when determining which translation to give a user based on their browser header, but can be selected by setting the Preview Languages on the Dark Language setting page.
This middleware must be placed before the LocaleMiddleware, but after the SessionMiddleware.
- class openedx.core.djangoapps.dark_lang.middleware.DarkLangMiddleware(get_response)#
Bases:
MiddlewareMixinMiddleware for dark-launching languages.
This is configured by creating
DarkLangConfigrows in the database, using the django admin site.- property beta_langs#
Current list of beta languages
- process_request(request)#
Prevent user from requesting un-released languages except by using the preview-lang query string.
- process_response(request, response)#
Apply user’s dark lang preference as a cookie for future requests.
- property released_langs#
Current list of released languages
openedx.core.djangoapps.dark_lang.models module#
Models for the dark-launching languages
- class openedx.core.djangoapps.dark_lang.models.DarkLangConfig(*args, **kwargs)#
Bases:
ConfigurationModelConfiguration for the dark_lang django app.
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- beta_languages#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property beta_languages_list#
beta_languagesas a list of language codes.Example: [‘it’, ‘de-at’, ‘es’, ‘pt-br’]
- change_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- changed_by#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- changed_by_id#
- enable_beta_languages#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- enabled#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
- get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- released_languages#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property released_languages_list#
released_languagesas a list of language codes.Example: [‘it’, ‘de-at’, ‘es’, ‘pt-br’]
openedx.core.djangoapps.dark_lang.urls module#
Contains all the URLs for the Dark Language Support App
openedx.core.djangoapps.dark_lang.views module#
Views file for the Darklang Django App
- class openedx.core.djangoapps.dark_lang.views.PreviewLanguageFragmentView(**kwargs)#
Bases:
EdxFragmentViewView used when a user is attempting to change the preview language using Darklang.
Expected Behavior: GET - returns a form for setting/resetting the user’s dark language POST - updates or clears the setting to the given dark language
- create_base_standalone_context(request, fragment, **kwargs)#
Creates the base context for rendering a fragment as a standalone page.
- get(request, *args, **kwargs)#
Renders the fragment to control the preview language.
- post(request, **kwargs)#
Accept requests to update the preview language.
- render_to_fragment(request, course_id=None, **kwargs)#
Renders the language preview view as a fragment.
- standalone_page_title(request, fragment, **kwargs)#
Returns the page title for the standalone update page.
Module contents#
Language Translation Dark Launching#
This app adds the ability to launch language translations that are only accessible through the use of a specific query parameter (and are not activated by browser settings).
Installation#
Add the DarkLangMiddleware to your list of MIDDLEWARE.
It must come after the SessionMiddleware, and before the LocaleMiddleware.
Run migrations to install the configuration table.
Use the admin site to add a new DarkLangConfig that is enabled, and lists the
languages that should be released.