

def add_default_language_settings(languages_list, var_name='PARLER_LANGUAGES', **extra_defaults):
    "\n    Apply extra defaults to the language settings.\n    This function can also be used by other packages to\n    create their own variation of ``PARLER_LANGUAGES`` with extra fields.\n    For example::\n\n        from django.conf import settings\n        from parler import appsettings as parler_appsettings\n\n        # Create local names, which are based on the global parler settings\n        MYAPP_DEFAULT_LANGUAGE_CODE = getattr(settings, 'MYAPP_DEFAULT_LANGUAGE_CODE', parler_appsettings.PARLER_DEFAULT_LANGUAGE_CODE)\n        MYAPP_LANGUAGES = getattr(settings, 'MYAPP_LANGUAGES', parler_appsettings.PARLER_LANGUAGES)\n\n        # Apply the defaults to the languages\n        MYAPP_LANGUAGES = parler_appsettings.add_default_language_settings(MYAPP_LANGUAGES, 'MYAPP_LANGUAGES',\n            code=MYAPP_DEFAULT_LANGUAGE_CODE,\n            fallback=MYAPP_DEFAULT_LANGUAGE_CODE,\n            hide_untranslated=False\n        )\n\n    The returned object will be an :class:`~parler.utils.conf.LanguagesSetting` object,\n    which adds additional methods to the :class:`dict` object.\n\n    :param languages_list: The settings, in :ref:`PARLER_LANGUAGES` format.\n    :param var_name: The name of your variable, for debugging output.\n    :param extra_defaults: Any defaults to override in the ``languages_list['default']`` section, e.g. ``code``, ``fallback``, ``hide_untranslated``.\n    :return: The updated ``languages_list`` with all defaults applied to all sections.\n    :rtype: LanguagesSetting\n    "
    languages_list = LanguagesSetting(languages_list)
    languages_list.setdefault('default', {
        
    })
    defaults = languages_list['default']
    defaults.setdefault('hide_untranslated', False)
    if ('fallback' in defaults):
        defaults['fallbacks'] = [defaults.pop('fallback')]
    if ('fallback' in extra_defaults):
        extra_defaults['fallbacks'] = [extra_defaults.pop('fallback')]
    defaults.update(extra_defaults)
    if ('code' not in defaults):
        from parler import appsettings
        defaults['code'] = appsettings.PARLER_DEFAULT_LANGUAGE_CODE
    if ('fallbacks' not in defaults):
        from parler import appsettings
        defaults['fallbacks'] = [appsettings.PARLER_DEFAULT_LANGUAGE_CODE]
    if (not is_supported_django_language(defaults['code'])):
        raise ImproperlyConfigured("The value for {0}['defaults']['code'] ('{1}') does not exist in LANGUAGES".format(var_name, defaults['code']))
    for (site_id, lang_choices) in six.iteritems(languages_list):
        if (site_id == 'default'):
            continue
        if (not isinstance(lang_choices, (list, tuple))):
            raise ImproperlyConfigured('{0}[{1}] should be a tuple of language choices!'.format(var_name, site_id))
        for (i, choice) in enumerate(lang_choices):
            if (not is_supported_django_language(choice['code'])):
                raise ImproperlyConfigured("{0}[{1}][{2}]['code'] does not exist in LANGUAGES".format(var_name, site_id, i))
            for (key, value) in six.iteritems(defaults):
                choice.setdefault(key, value)
    return languages_list

dataset/ETHPy150Open edoburu/django-parler/parler/utils/conf.py add_default_language_settings/original