def METHOD_NAME(context, page):
    """
    The current requirement for this is really tricky.
    See https://github.com/unicef/iogt/pull/955#issuecomment-1008277982 for more
    context on why this logic is complicated.
    """
    language_options = list()
    locales = Locale.objects.select_related('locale_detail').all()
    current_language = translation.get_language_info(translation.get_language())
    try:
        if resolve(context.request.path_info).url_name == 'translation-not-found':
            page = get_object_or_404(Page, pk=context.request.GET.get('page'), live=True)
    except Resolver404:
        pass
    for locale in locales:
        option = {}
        try:
            language = translation.get_language_info(locale.language_code)
            option['language'] = language
            option['selected'] = locale.language_code == current_language.get('code')
        except:
            continue
        try:
            should_append = locale.locale_detail.is_active
        except LocaleDetail.DoesNotExist:
            should_append = True
        if should_append:
            if page:  # If the current URL belongs to a wagtail page
                translated_page = page and page.get_translation_or_none(locale)
                if translated_page and translated_page.live:
                    url = translated_page.url
                else:
                    translated_url = translate_url(reverse('translation-not-found'), locale.language_code)
                    url = f'{translated_url}?page={page.id}'
            else:  # If the current URL belongs to a django view
                url = translate_url(context.request.path_info, locale.language_code)
            option['url'] = url
            language_options.append(option)
    context.update({
        'language_options': language_options,
        'current_language': current_language,
    })
    return context