Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Alternate url tags

Pacu21842f0151e42
diff --git a/saleor/core/templatetags/urls.py b/saleor/core/templatetags/urls.py
index 8297dbd727..ecfc3a5c40 100644
--- a/saleor/core/templatetags/urls.py
+++ b/saleor/core/templatetags/urls.py
@@ -1,4 +1,5 @@
from django import template
+from django.urls import translate_url as django_translate_url
register = template.Library()
@@ -6,3 +7,8 @@ register = template.Library()
@register.simple_tag
def build_absolute_uri(request, location):
return request.build_absolute_uri(location)
+
+
+def translate_url(url, lang_code):
+ return django_translate_url(url, lang_code)
diff --git a/templates/base.html b/templates/base.html
index 83e938b1a6..84c0cdf719 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -3,6 +3,7 @@
{% load staticfiles %}
{% load render_bundle from webpack_loader %}
{% load placeholder %}
+{% load translate_url from urls %}
<html lang="{{ LANGUAGE_CODE }}" class="no-js" data-shipping-options-url="{% url 'cart:shipping-options' %}" data-cart-summary-url="{% url 'cart:cart-summary' %}">
<head>
@@ -18,6 +19,10 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="{{ site.name }}">
<meta name="og:type" content="website">
+ {% get_available_languages as LANGUAGES %}
+ {% for lang_code, language_name in LANGUAGES %}
+ <link rel="alternate" hreflang="{{ lang_code }}" href="{% translate_url url=request.path lang_code=lang_code %}" />
+ {% endfor %}
{% endblock meta %}
{% include 'favicon.html' %}