I want my Django site to be available in both English and Azerbaijani languages.
This is how I wrote the codes for it. However, I do not know what is true. Is there an alternative? Does this method affect the speed of the site?
in my view :
def change_Lang(request):
referer = request.META.get('HTTP_REFERER')
lang = request.GET.get("pylang", "en")
pylang = request.session.get("pylang", None)
if lang != "az" and lang != "en": lang = "en"
if pylang == None: request.session["pylang"] = lang
if pylang != lang: request.session["pylang"] = lang
if referer: return HttpResponseRedirect(referer)
return redirect("home")
in my templatetag:
@register.simple_tag
def pylang(value, en, az):
if value == "en": return en
elif value == "az": return az
else: return en
in my template :
{% load pylang %}
{% pylang request.session.pylang "About - PyTerminator.com" "Haqqımızda - PyTerminator.com" %}
I want to know if this method has a negative effect on the speed of the site?
What is the alternative?
Suggest better options. Thanks in advance)
New contributor
Mushvig Shukurov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1