Return the default language given the notebook metadata, and a file extension

def default_language_from_metadata_and_ext(metadata, ext):
    """Return the default language given the notebook metadata, and a file extension"""
    default_from_ext = _SCRIPT_EXTENSIONS.get(ext, {}).get('language', 'python')

    language = (metadata.get('jupytext', {}).get('main_language')
                or metadata.get('kernelspec', {}).get('language')
                or default_from_ext)

    if language.startswith('C++'):
        language = 'c++'

    return language