import re

from django import template
from django.conf import settings

register = template.Library()


@register.simple_tag
def barebone_strip_language_code(request):
    path = request.path
    if settings.USE_I18N and hasattr(request, "LANGUAGE_CODE"):
        return re.sub("^/%s/" % request.LANGUAGE_CODE, "/", path)
    return path
