parler.utils.conf module¶
The configuration wrappers that are used for PARLER_LANGUAGES.
-
class
parler.utils.conf.
LanguagesSetting
¶ Bases:
dict
This is the actual object type of the PARLER_LANGUAGES setting. Besides the regular
dict
behavior, it also adds some additional methods.-
get_active_choices
(language_code=None, site_id=None)¶ Find out which translations should be visible in the site. It returns a list with either a single choice (the current language), or a list with the current language + fallback language.
-
get_default_language
()¶ Return the default language.
-
get_fallback_language
(language_code=None, site_id=None)¶ Find out what the fallback language is for a given language choice.
Deprecated since version 1.5: Use
get_fallback_languages()
instead.
-
get_fallback_languages
(language_code=None, site_id=None)¶ Find out what the fallback language is for a given language choice.
-
get_first_language
(site_id=None)¶ Return the first language for the current site. This can be used for user interfaces, where the languages are displayed in tabs.
-
get_language
(language_code, site_id=None)¶ Return the language settings for the current site
This function can be used with other settings variables to support modules which create their own variation of the
PARLER_LANGUAGES
setting. For an example, seeadd_default_language_settings()
.
-
-
parler.utils.conf.
add_default_language_settings
(languages_list, var_name='PARLER_LANGUAGES', **extra_defaults)¶ Apply extra defaults to the language settings. This function can also be used by other packages to create their own variation of
PARLER_LANGUAGES
with extra fields. For example:from django.conf import settings from parler import appsettings as parler_appsettings # Create local names, which are based on the global parler settings MYAPP_DEFAULT_LANGUAGE_CODE = getattr(settings, 'MYAPP_DEFAULT_LANGUAGE_CODE', parler_appsettings.PARLER_DEFAULT_LANGUAGE_CODE) MYAPP_LANGUAGES = getattr(settings, 'MYAPP_LANGUAGES', parler_appsettings.PARLER_LANGUAGES) # Apply the defaults to the languages MYAPP_LANGUAGES = parler_appsettings.add_default_language_settings(MYAPP_LANGUAGES, 'MYAPP_LANGUAGES', code=MYAPP_DEFAULT_LANGUAGE_CODE, fallback=MYAPP_DEFAULT_LANGUAGE_CODE, hide_untranslated=False )
The returned object will be an
LanguagesSetting
object, which adds additional methods to thedict
object.Parameters: - languages_list – The settings, in PARLER_LANGUAGES format.
- var_name – The name of your variable, for debugging output.
- extra_defaults – Any defaults to override in the
languages_list['default']
section, e.g.code
,fallback
,hide_untranslated
.
Returns: The updated
languages_list
with all defaults applied to all sections.Return type:
-
parler.utils.conf.
get_parler_languages_from_django_cms
(cms_languages=None)¶ Converts django CMS’ setting CMS_LANGUAGES into PARLER_LANGUAGES. Since CMS_LANGUAGES is a strict superset of PARLER_LANGUAGES, we do a bit of cleansing to remove irrelevant items.