@register.simple_tag(takes_context=True)
def translate_url(context, language):
    """
    Translates the current URL for the given language code, eg:

        {% translate_url de %}
    """
    try:
        request = context["request"]
    except __HOLE__:
        return ""
    view = resolve(request.path)
    current_language = translation.get_language()
    translation.activate(language)
    try:
        url = reverse(view.func, args=view.args, kwargs=view.kwargs)
    except NoReverseMatch:
        try:
            url_name = (view.url_name if not view.namespace
                        else '%s:%s' % (view.namespace, view.url_name))
            url = reverse(url_name, args=view.args, kwargs=view.kwargs)
        except NoReverseMatch:
            url_name = "admin:" + view.url_name
            url = reverse(url_name, args=view.args, kwargs=view.kwargs)
    translation.activate(current_language)
    if context['request'].META["QUERY_STRING"]:
        url += "?" + context['request'].META["QUERY_STRING"]
    return url
dataset/ETHPy150Open stephenmcd/mezzanine/mezzanine/core/templatetags/mezzanine_tags.py/translate_url