def get_default_language(language_code=None):
    """
    Returns default language depending on settings.LANGUAGE_CODE merged with
    best match from settings.LANGUAGES

    Returns: language_code

    Raises ImproperlyConfigured if no match found
    """

    if not language_code:
        language_code = settings.LANGUAGE_CODE

    languages = dict(settings.LANGUAGES).keys()

    # first try if there is an exact language
    if language_code in languages:
        return language_code

    # otherwise split the language code if possible, so iso3
    language_code = language_code.split("-")[0]

    if language_code not in languages:
        raise ImproperlyConfigured("No match in LANGUAGES for LANGUAGE_CODE %s" % settings.LANGUAGE_CODE)

    return language_code
Returns default language depending on settings.LANGUAGE_CODE merged with
    best match from settings.LANGUAGES

    Returns: language_code

    Raises ImproperlyConfigured if no match found