openedx.core.djangoapps.lang_pref package#

Submodules#

openedx.core.djangoapps.lang_pref.api module#

Python API for language and translation management.

class openedx.core.djangoapps.lang_pref.api.Language(code, name)#

Bases: tuple

code#

Alias for field number 0

name#

Alias for field number 1

openedx.core.djangoapps.lang_pref.api.all_languages()#

Retrieve the list of all languages, translated and sorted.

Returns:

the language names are translated in the current activated language and the results sorted alphabetically.

Return type:

list of (language code (str), language name (str))

openedx.core.djangoapps.lang_pref.api.footer_language_selector_is_enabled()#

Return true if the footer language selector has been enabled via settings or site-specific configuration.

openedx.core.djangoapps.lang_pref.api.get_closest_released_language(target_language_code)#

Return the language code that most closely matches the target and is fully supported by the LMS, or None if there are no fully supported languages that match the target.

openedx.core.djangoapps.lang_pref.api.header_language_selector_is_enabled()#

Return true if the header language selector has been enabled via settings or site-specific configuration.

openedx.core.djangoapps.lang_pref.api.released_languages()#

Retrieve the list of released languages.

Constructs a list of Language tuples by intersecting the list of valid language tuples with the list of released language codes.

Returns:

Languages in which full translations are available.

Return type:

list of Language

Example

>>> print released_languages()
[Language(code='en', name=u'English'), Language(code='fr', name=u'Français')]

openedx.core.djangoapps.lang_pref.helpers module#

Language preference cookie helper functions

Return the language cookie stored in the request object.

Set the language cookie in the response object.

Remove the language cookie from the response object.

openedx.core.djangoapps.lang_pref.middleware module#

Middleware for Language Preferences

class openedx.core.djangoapps.lang_pref.middleware.LanguagePreferenceMiddleware(get_response)#

Bases: MiddlewareMixin

Middleware for user preferences.

Ensures that, once set, a user’s preferences are reflected in the page whenever they are logged in.

process_request(request)#

If a user’s UserPreference contains a language preference, use the user’s preference. Save the current language preference cookie as the user’s preferred language.

If you specify the LANGUAGE_CODE in SiteConfiguration, it will have a higher priority than the user’s language preference.

process_response(request, response)#

openedx.core.djangoapps.lang_pref.views module#

Language Preference Views

openedx.core.djangoapps.lang_pref.views.update_language(request)#

Update the language cookie.

Module contents#

Useful information for setting the language preference